adafruit / Adafruit_nRF52_Arduino

Adafruit code for the Nordic nRF52 BLE SoC on Arduino
Other
623 stars 497 forks source link

label new/delete as weakly bound. So that apps can redefine as needed #532

Closed geeksville closed 3 years ago

geeksville commented 4 years ago

Sometimes app developers need to redefine new/delete for debugging or other purposes. This changes the definitions to have the weak attribute, so that will be allowed by the linker rather than throwing an error.

hathach commented 4 years ago

can you explain it in more detail

geeksville commented 4 years ago

sure. It is often super useful to redefine new/delete so you can debug, track all allocations. And in most (all? it might be a requirement of the C++ language spec?) libraries new/delete are declared with weak binding, so applications can define their own implementation if needed.

The adafruit_nrf52 lib was not marking their implementation as weakly bound. So any attempt to redefine it would be declared illegal by the linker.

More info here: https://stackoverflow.com/a/8186116

hathach commented 3 years ago

Closed since I don’t think it is necessary. For debug purpose please modify the func directly. We can’t have all function as weak for override