1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00

new w/ OOM now aborts by defaults, or throw an exception (#7536)

* replace `new` by `new (std::nothrow)`, remove `arduino_new`

* deleted:    arduino_new/arduino_new.ino

* fixes

* remove (std::nothrow) where nullptr case is not handled
remove legacy new management

* new w/ OOM raises an exception, shows the caller address for decoders

* overwrite weak `new (std::nothrow)` calls

* fix displaying caller address

* board generator: remove comments, remove now useless define

Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
Co-authored-by: Develo <deveyes@gmail.com>
This commit is contained in:
Develo 2020-08-31 01:19:20 -04:00 committed by GitHub
commit 5b767a37eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 134 additions and 423 deletions

View File

@ -49,11 +49,8 @@ generic.menu.vt.heap=Heap
generic.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
generic.menu.vt.iram=IRAM
generic.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
generic.menu.exception.legacy=Legacy (new can return nullptr)
generic.menu.exception.legacy.build.exception_flags=-fno-exceptions
generic.menu.exception.legacy.build.stdcpp_lib=-lstdc++
generic.menu.exception.disabled=Disabled (new can abort)
generic.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
generic.menu.exception.disabled=Disabled (new aborts on oom)
generic.menu.exception.disabled.build.exception_flags=-fno-exceptions
generic.menu.exception.disabled.build.stdcpp_lib=-lstdc++
generic.menu.exception.enabled=Enabled
generic.menu.exception.enabled.build.exception_flags=-fexceptions
@ -521,11 +518,8 @@ esp8285.menu.vt.heap=Heap
esp8285.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
esp8285.menu.vt.iram=IRAM
esp8285.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
esp8285.menu.exception.legacy=Legacy (new can return nullptr)
esp8285.menu.exception.legacy.build.exception_flags=-fno-exceptions
esp8285.menu.exception.legacy.build.stdcpp_lib=-lstdc++
esp8285.menu.exception.disabled=Disabled (new can abort)
esp8285.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
esp8285.menu.exception.disabled=Disabled (new aborts on oom)
esp8285.menu.exception.disabled.build.exception_flags=-fno-exceptions
esp8285.menu.exception.disabled.build.stdcpp_lib=-lstdc++
esp8285.menu.exception.enabled=Enabled
esp8285.menu.exception.enabled.build.exception_flags=-fexceptions
@ -871,11 +865,8 @@ espduino.menu.vt.heap=Heap
espduino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espduino.menu.vt.iram=IRAM
espduino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espduino.menu.exception.legacy=Legacy (new can return nullptr)
espduino.menu.exception.legacy.build.exception_flags=-fno-exceptions
espduino.menu.exception.legacy.build.stdcpp_lib=-lstdc++
espduino.menu.exception.disabled=Disabled (new can abort)
espduino.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
espduino.menu.exception.disabled=Disabled (new aborts on oom)
espduino.menu.exception.disabled.build.exception_flags=-fno-exceptions
espduino.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espduino.menu.exception.enabled=Enabled
espduino.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1060,11 +1051,8 @@ huzzah.menu.vt.heap=Heap
huzzah.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
huzzah.menu.vt.iram=IRAM
huzzah.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
huzzah.menu.exception.legacy=Legacy (new can return nullptr)
huzzah.menu.exception.legacy.build.exception_flags=-fno-exceptions
huzzah.menu.exception.legacy.build.stdcpp_lib=-lstdc++
huzzah.menu.exception.disabled=Disabled (new can abort)
huzzah.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
huzzah.menu.exception.disabled=Disabled (new aborts on oom)
huzzah.menu.exception.disabled.build.exception_flags=-fno-exceptions
huzzah.menu.exception.disabled.build.stdcpp_lib=-lstdc++
huzzah.menu.exception.enabled=Enabled
huzzah.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1250,11 +1238,8 @@ inventone.menu.vt.heap=Heap
inventone.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
inventone.menu.vt.iram=IRAM
inventone.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
inventone.menu.exception.legacy=Legacy (new can return nullptr)
inventone.menu.exception.legacy.build.exception_flags=-fno-exceptions
inventone.menu.exception.legacy.build.stdcpp_lib=-lstdc++
inventone.menu.exception.disabled=Disabled (new can abort)
inventone.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
inventone.menu.exception.disabled=Disabled (new aborts on oom)
inventone.menu.exception.disabled.build.exception_flags=-fno-exceptions
inventone.menu.exception.disabled.build.stdcpp_lib=-lstdc++
inventone.menu.exception.enabled=Enabled
inventone.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1440,11 +1425,8 @@ cw01.menu.vt.heap=Heap
cw01.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
cw01.menu.vt.iram=IRAM
cw01.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
cw01.menu.exception.legacy=Legacy (new can return nullptr)
cw01.menu.exception.legacy.build.exception_flags=-fno-exceptions
cw01.menu.exception.legacy.build.stdcpp_lib=-lstdc++
cw01.menu.exception.disabled=Disabled (new can abort)
cw01.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
cw01.menu.exception.disabled=Disabled (new aborts on oom)
cw01.menu.exception.disabled.build.exception_flags=-fno-exceptions
cw01.menu.exception.disabled.build.stdcpp_lib=-lstdc++
cw01.menu.exception.enabled=Enabled
cw01.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1633,11 +1615,8 @@ espresso_lite_v1.menu.vt.heap=Heap
espresso_lite_v1.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espresso_lite_v1.menu.vt.iram=IRAM
espresso_lite_v1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espresso_lite_v1.menu.exception.legacy=Legacy (new can return nullptr)
espresso_lite_v1.menu.exception.legacy.build.exception_flags=-fno-exceptions
espresso_lite_v1.menu.exception.legacy.build.stdcpp_lib=-lstdc++
espresso_lite_v1.menu.exception.disabled=Disabled (new can abort)
espresso_lite_v1.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
espresso_lite_v1.menu.exception.disabled=Disabled (new aborts on oom)
espresso_lite_v1.menu.exception.disabled.build.exception_flags=-fno-exceptions
espresso_lite_v1.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espresso_lite_v1.menu.exception.enabled=Enabled
espresso_lite_v1.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1826,11 +1805,8 @@ espresso_lite_v2.menu.vt.heap=Heap
espresso_lite_v2.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espresso_lite_v2.menu.vt.iram=IRAM
espresso_lite_v2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espresso_lite_v2.menu.exception.legacy=Legacy (new can return nullptr)
espresso_lite_v2.menu.exception.legacy.build.exception_flags=-fno-exceptions
espresso_lite_v2.menu.exception.legacy.build.stdcpp_lib=-lstdc++
espresso_lite_v2.menu.exception.disabled=Disabled (new can abort)
espresso_lite_v2.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
espresso_lite_v2.menu.exception.disabled=Disabled (new aborts on oom)
espresso_lite_v2.menu.exception.disabled.build.exception_flags=-fno-exceptions
espresso_lite_v2.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espresso_lite_v2.menu.exception.enabled=Enabled
espresso_lite_v2.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2019,11 +1995,8 @@ phoenix_v1.menu.vt.heap=Heap
phoenix_v1.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
phoenix_v1.menu.vt.iram=IRAM
phoenix_v1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
phoenix_v1.menu.exception.legacy=Legacy (new can return nullptr)
phoenix_v1.menu.exception.legacy.build.exception_flags=-fno-exceptions
phoenix_v1.menu.exception.legacy.build.stdcpp_lib=-lstdc++
phoenix_v1.menu.exception.disabled=Disabled (new can abort)
phoenix_v1.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
phoenix_v1.menu.exception.disabled=Disabled (new aborts on oom)
phoenix_v1.menu.exception.disabled.build.exception_flags=-fno-exceptions
phoenix_v1.menu.exception.disabled.build.stdcpp_lib=-lstdc++
phoenix_v1.menu.exception.enabled=Enabled
phoenix_v1.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2212,11 +2185,8 @@ phoenix_v2.menu.vt.heap=Heap
phoenix_v2.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
phoenix_v2.menu.vt.iram=IRAM
phoenix_v2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
phoenix_v2.menu.exception.legacy=Legacy (new can return nullptr)
phoenix_v2.menu.exception.legacy.build.exception_flags=-fno-exceptions
phoenix_v2.menu.exception.legacy.build.stdcpp_lib=-lstdc++
phoenix_v2.menu.exception.disabled=Disabled (new can abort)
phoenix_v2.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
phoenix_v2.menu.exception.disabled=Disabled (new aborts on oom)
phoenix_v2.menu.exception.disabled.build.exception_flags=-fno-exceptions
phoenix_v2.menu.exception.disabled.build.stdcpp_lib=-lstdc++
phoenix_v2.menu.exception.enabled=Enabled
phoenix_v2.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2405,11 +2375,8 @@ nodemcu.menu.vt.heap=Heap
nodemcu.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
nodemcu.menu.vt.iram=IRAM
nodemcu.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
nodemcu.menu.exception.legacy=Legacy (new can return nullptr)
nodemcu.menu.exception.legacy.build.exception_flags=-fno-exceptions
nodemcu.menu.exception.legacy.build.stdcpp_lib=-lstdc++
nodemcu.menu.exception.disabled=Disabled (new can abort)
nodemcu.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
nodemcu.menu.exception.disabled=Disabled (new aborts on oom)
nodemcu.menu.exception.disabled.build.exception_flags=-fno-exceptions
nodemcu.menu.exception.disabled.build.stdcpp_lib=-lstdc++
nodemcu.menu.exception.enabled=Enabled
nodemcu.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2595,11 +2562,8 @@ nodemcuv2.menu.vt.heap=Heap
nodemcuv2.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
nodemcuv2.menu.vt.iram=IRAM
nodemcuv2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
nodemcuv2.menu.exception.legacy=Legacy (new can return nullptr)
nodemcuv2.menu.exception.legacy.build.exception_flags=-fno-exceptions
nodemcuv2.menu.exception.legacy.build.stdcpp_lib=-lstdc++
nodemcuv2.menu.exception.disabled=Disabled (new can abort)
nodemcuv2.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
nodemcuv2.menu.exception.disabled=Disabled (new aborts on oom)
nodemcuv2.menu.exception.disabled.build.exception_flags=-fno-exceptions
nodemcuv2.menu.exception.disabled.build.stdcpp_lib=-lstdc++
nodemcuv2.menu.exception.enabled=Enabled
nodemcuv2.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2789,11 +2753,8 @@ modwifi.menu.vt.heap=Heap
modwifi.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
modwifi.menu.vt.iram=IRAM
modwifi.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
modwifi.menu.exception.legacy=Legacy (new can return nullptr)
modwifi.menu.exception.legacy.build.exception_flags=-fno-exceptions
modwifi.menu.exception.legacy.build.stdcpp_lib=-lstdc++
modwifi.menu.exception.disabled=Disabled (new can abort)
modwifi.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
modwifi.menu.exception.disabled=Disabled (new aborts on oom)
modwifi.menu.exception.disabled.build.exception_flags=-fno-exceptions
modwifi.menu.exception.disabled.build.stdcpp_lib=-lstdc++
modwifi.menu.exception.enabled=Enabled
modwifi.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2999,11 +2960,8 @@ thing.menu.vt.heap=Heap
thing.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
thing.menu.vt.iram=IRAM
thing.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
thing.menu.exception.legacy=Legacy (new can return nullptr)
thing.menu.exception.legacy.build.exception_flags=-fno-exceptions
thing.menu.exception.legacy.build.stdcpp_lib=-lstdc++
thing.menu.exception.disabled=Disabled (new can abort)
thing.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
thing.menu.exception.disabled=Disabled (new aborts on oom)
thing.menu.exception.disabled.build.exception_flags=-fno-exceptions
thing.menu.exception.disabled.build.stdcpp_lib=-lstdc++
thing.menu.exception.enabled=Enabled
thing.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3189,11 +3147,8 @@ thingdev.menu.vt.heap=Heap
thingdev.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
thingdev.menu.vt.iram=IRAM
thingdev.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
thingdev.menu.exception.legacy=Legacy (new can return nullptr)
thingdev.menu.exception.legacy.build.exception_flags=-fno-exceptions
thingdev.menu.exception.legacy.build.stdcpp_lib=-lstdc++
thingdev.menu.exception.disabled=Disabled (new can abort)
thingdev.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
thingdev.menu.exception.disabled=Disabled (new aborts on oom)
thingdev.menu.exception.disabled.build.exception_flags=-fno-exceptions
thingdev.menu.exception.disabled.build.stdcpp_lib=-lstdc++
thingdev.menu.exception.enabled=Enabled
thingdev.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3379,11 +3334,8 @@ blynk.menu.vt.heap=Heap
blynk.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
blynk.menu.vt.iram=IRAM
blynk.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
blynk.menu.exception.legacy=Legacy (new can return nullptr)
blynk.menu.exception.legacy.build.exception_flags=-fno-exceptions
blynk.menu.exception.legacy.build.stdcpp_lib=-lstdc++
blynk.menu.exception.disabled=Disabled (new can abort)
blynk.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
blynk.menu.exception.disabled=Disabled (new aborts on oom)
blynk.menu.exception.disabled.build.exception_flags=-fno-exceptions
blynk.menu.exception.disabled.build.stdcpp_lib=-lstdc++
blynk.menu.exception.enabled=Enabled
blynk.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3569,11 +3521,8 @@ esp210.menu.vt.heap=Heap
esp210.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
esp210.menu.vt.iram=IRAM
esp210.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
esp210.menu.exception.legacy=Legacy (new can return nullptr)
esp210.menu.exception.legacy.build.exception_flags=-fno-exceptions
esp210.menu.exception.legacy.build.stdcpp_lib=-lstdc++
esp210.menu.exception.disabled=Disabled (new can abort)
esp210.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
esp210.menu.exception.disabled=Disabled (new aborts on oom)
esp210.menu.exception.disabled.build.exception_flags=-fno-exceptions
esp210.menu.exception.disabled.build.stdcpp_lib=-lstdc++
esp210.menu.exception.enabled=Enabled
esp210.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3759,11 +3708,8 @@ d1_mini.menu.vt.heap=Heap
d1_mini.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
d1_mini.menu.vt.iram=IRAM
d1_mini.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
d1_mini.menu.exception.legacy=Legacy (new can return nullptr)
d1_mini.menu.exception.legacy.build.exception_flags=-fno-exceptions
d1_mini.menu.exception.legacy.build.stdcpp_lib=-lstdc++
d1_mini.menu.exception.disabled=Disabled (new can abort)
d1_mini.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
d1_mini.menu.exception.disabled=Disabled (new aborts on oom)
d1_mini.menu.exception.disabled.build.exception_flags=-fno-exceptions
d1_mini.menu.exception.disabled.build.stdcpp_lib=-lstdc++
d1_mini.menu.exception.enabled=Enabled
d1_mini.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3949,11 +3895,8 @@ d1_mini_pro.menu.vt.heap=Heap
d1_mini_pro.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
d1_mini_pro.menu.vt.iram=IRAM
d1_mini_pro.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
d1_mini_pro.menu.exception.legacy=Legacy (new can return nullptr)
d1_mini_pro.menu.exception.legacy.build.exception_flags=-fno-exceptions
d1_mini_pro.menu.exception.legacy.build.stdcpp_lib=-lstdc++
d1_mini_pro.menu.exception.disabled=Disabled (new can abort)
d1_mini_pro.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
d1_mini_pro.menu.exception.disabled=Disabled (new aborts on oom)
d1_mini_pro.menu.exception.disabled.build.exception_flags=-fno-exceptions
d1_mini_pro.menu.exception.disabled.build.stdcpp_lib=-lstdc++
d1_mini_pro.menu.exception.enabled=Enabled
d1_mini_pro.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4122,11 +4065,8 @@ d1_mini_lite.menu.vt.heap=Heap
d1_mini_lite.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
d1_mini_lite.menu.vt.iram=IRAM
d1_mini_lite.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
d1_mini_lite.menu.exception.legacy=Legacy (new can return nullptr)
d1_mini_lite.menu.exception.legacy.build.exception_flags=-fno-exceptions
d1_mini_lite.menu.exception.legacy.build.stdcpp_lib=-lstdc++
d1_mini_lite.menu.exception.disabled=Disabled (new can abort)
d1_mini_lite.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
d1_mini_lite.menu.exception.disabled=Disabled (new aborts on oom)
d1_mini_lite.menu.exception.disabled.build.exception_flags=-fno-exceptions
d1_mini_lite.menu.exception.disabled.build.stdcpp_lib=-lstdc++
d1_mini_lite.menu.exception.enabled=Enabled
d1_mini_lite.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4352,11 +4292,8 @@ d1.menu.vt.heap=Heap
d1.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
d1.menu.vt.iram=IRAM
d1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
d1.menu.exception.legacy=Legacy (new can return nullptr)
d1.menu.exception.legacy.build.exception_flags=-fno-exceptions
d1.menu.exception.legacy.build.stdcpp_lib=-lstdc++
d1.menu.exception.disabled=Disabled (new can abort)
d1.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
d1.menu.exception.disabled=Disabled (new aborts on oom)
d1.menu.exception.disabled.build.exception_flags=-fno-exceptions
d1.menu.exception.disabled.build.stdcpp_lib=-lstdc++
d1.menu.exception.enabled=Enabled
d1.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4542,11 +4479,8 @@ espino.menu.vt.heap=Heap
espino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espino.menu.vt.iram=IRAM
espino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espino.menu.exception.legacy=Legacy (new can return nullptr)
espino.menu.exception.legacy.build.exception_flags=-fno-exceptions
espino.menu.exception.legacy.build.stdcpp_lib=-lstdc++
espino.menu.exception.disabled=Disabled (new can abort)
espino.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
espino.menu.exception.disabled=Disabled (new aborts on oom)
espino.menu.exception.disabled.build.exception_flags=-fno-exceptions
espino.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espino.menu.exception.enabled=Enabled
espino.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4735,11 +4669,8 @@ espinotee.menu.vt.heap=Heap
espinotee.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espinotee.menu.vt.iram=IRAM
espinotee.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espinotee.menu.exception.legacy=Legacy (new can return nullptr)
espinotee.menu.exception.legacy.build.exception_flags=-fno-exceptions
espinotee.menu.exception.legacy.build.stdcpp_lib=-lstdc++
espinotee.menu.exception.disabled=Disabled (new can abort)
espinotee.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
espinotee.menu.exception.disabled=Disabled (new aborts on oom)
espinotee.menu.exception.disabled.build.exception_flags=-fno-exceptions
espinotee.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espinotee.menu.exception.enabled=Enabled
espinotee.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4942,11 +4873,8 @@ wifinfo.menu.vt.heap=Heap
wifinfo.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
wifinfo.menu.vt.iram=IRAM
wifinfo.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
wifinfo.menu.exception.legacy=Legacy (new can return nullptr)
wifinfo.menu.exception.legacy.build.exception_flags=-fno-exceptions
wifinfo.menu.exception.legacy.build.stdcpp_lib=-lstdc++
wifinfo.menu.exception.disabled=Disabled (new can abort)
wifinfo.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
wifinfo.menu.exception.disabled=Disabled (new aborts on oom)
wifinfo.menu.exception.disabled.build.exception_flags=-fno-exceptions
wifinfo.menu.exception.disabled.build.stdcpp_lib=-lstdc++
wifinfo.menu.exception.enabled=Enabled
wifinfo.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5191,11 +5119,8 @@ arduino-esp8266.menu.vt.heap=Heap
arduino-esp8266.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
arduino-esp8266.menu.vt.iram=IRAM
arduino-esp8266.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
arduino-esp8266.menu.exception.legacy=Legacy (new can return nullptr)
arduino-esp8266.menu.exception.legacy.build.exception_flags=-fno-exceptions
arduino-esp8266.menu.exception.legacy.build.stdcpp_lib=-lstdc++
arduino-esp8266.menu.exception.disabled=Disabled (new can abort)
arduino-esp8266.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
arduino-esp8266.menu.exception.disabled=Disabled (new aborts on oom)
arduino-esp8266.menu.exception.disabled.build.exception_flags=-fno-exceptions
arduino-esp8266.menu.exception.disabled.build.stdcpp_lib=-lstdc++
arduino-esp8266.menu.exception.enabled=Enabled
arduino-esp8266.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5382,11 +5307,8 @@ gen4iod.menu.vt.heap=Heap
gen4iod.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
gen4iod.menu.vt.iram=IRAM
gen4iod.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
gen4iod.menu.exception.legacy=Legacy (new can return nullptr)
gen4iod.menu.exception.legacy.build.exception_flags=-fno-exceptions
gen4iod.menu.exception.legacy.build.stdcpp_lib=-lstdc++
gen4iod.menu.exception.disabled=Disabled (new can abort)
gen4iod.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
gen4iod.menu.exception.disabled=Disabled (new aborts on oom)
gen4iod.menu.exception.disabled.build.exception_flags=-fno-exceptions
gen4iod.menu.exception.disabled.build.stdcpp_lib=-lstdc++
gen4iod.menu.exception.enabled=Enabled
gen4iod.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5640,11 +5562,8 @@ oak.menu.vt.heap=Heap
oak.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
oak.menu.vt.iram=IRAM
oak.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
oak.menu.exception.legacy=Legacy (new can return nullptr)
oak.menu.exception.legacy.build.exception_flags=-fno-exceptions
oak.menu.exception.legacy.build.stdcpp_lib=-lstdc++
oak.menu.exception.disabled=Disabled (new can abort)
oak.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
oak.menu.exception.disabled=Disabled (new aborts on oom)
oak.menu.exception.disabled.build.exception_flags=-fno-exceptions
oak.menu.exception.disabled.build.stdcpp_lib=-lstdc++
oak.menu.exception.enabled=Enabled
oak.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5830,11 +5749,8 @@ wifiduino.menu.vt.heap=Heap
wifiduino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
wifiduino.menu.vt.iram=IRAM
wifiduino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
wifiduino.menu.exception.legacy=Legacy (new can return nullptr)
wifiduino.menu.exception.legacy.build.exception_flags=-fno-exceptions
wifiduino.menu.exception.legacy.build.stdcpp_lib=-lstdc++
wifiduino.menu.exception.disabled=Disabled (new can abort)
wifiduino.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
wifiduino.menu.exception.disabled=Disabled (new aborts on oom)
wifiduino.menu.exception.disabled.build.exception_flags=-fno-exceptions
wifiduino.menu.exception.disabled.build.stdcpp_lib=-lstdc++
wifiduino.menu.exception.enabled=Enabled
wifiduino.menu.exception.enabled.build.exception_flags=-fexceptions
@ -6020,11 +5936,8 @@ wifi_slot.menu.vt.heap=Heap
wifi_slot.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
wifi_slot.menu.vt.iram=IRAM
wifi_slot.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
wifi_slot.menu.exception.legacy=Legacy (new can return nullptr)
wifi_slot.menu.exception.legacy.build.exception_flags=-fno-exceptions
wifi_slot.menu.exception.legacy.build.stdcpp_lib=-lstdc++
wifi_slot.menu.exception.disabled=Disabled (new can abort)
wifi_slot.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
wifi_slot.menu.exception.disabled=Disabled (new aborts on oom)
wifi_slot.menu.exception.disabled.build.exception_flags=-fno-exceptions
wifi_slot.menu.exception.disabled.build.stdcpp_lib=-lstdc++
wifi_slot.menu.exception.enabled=Enabled
wifi_slot.menu.exception.enabled.build.exception_flags=-fexceptions
@ -6324,11 +6237,8 @@ wiolink.menu.vt.heap=Heap
wiolink.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
wiolink.menu.vt.iram=IRAM
wiolink.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
wiolink.menu.exception.legacy=Legacy (new can return nullptr)
wiolink.menu.exception.legacy.build.exception_flags=-fno-exceptions
wiolink.menu.exception.legacy.build.stdcpp_lib=-lstdc++
wiolink.menu.exception.disabled=Disabled (new can abort)
wiolink.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
wiolink.menu.exception.disabled=Disabled (new aborts on oom)
wiolink.menu.exception.disabled.build.exception_flags=-fno-exceptions
wiolink.menu.exception.disabled.build.stdcpp_lib=-lstdc++
wiolink.menu.exception.enabled=Enabled
wiolink.menu.exception.enabled.build.exception_flags=-fexceptions
@ -6514,11 +6424,8 @@ espectro.menu.vt.heap=Heap
espectro.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espectro.menu.vt.iram=IRAM
espectro.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espectro.menu.exception.legacy=Legacy (new can return nullptr)
espectro.menu.exception.legacy.build.exception_flags=-fno-exceptions
espectro.menu.exception.legacy.build.stdcpp_lib=-lstdc++
espectro.menu.exception.disabled=Disabled (new can abort)
espectro.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
espectro.menu.exception.disabled=Disabled (new aborts on oom)
espectro.menu.exception.disabled.build.exception_flags=-fno-exceptions
espectro.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espectro.menu.exception.enabled=Enabled
espectro.menu.exception.enabled.build.exception_flags=-fexceptions
@ -6704,11 +6611,8 @@ eduinowifi.menu.vt.heap=Heap
eduinowifi.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
eduinowifi.menu.vt.iram=IRAM
eduinowifi.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
eduinowifi.menu.exception.legacy=Legacy (new can return nullptr)
eduinowifi.menu.exception.legacy.build.exception_flags=-fno-exceptions
eduinowifi.menu.exception.legacy.build.stdcpp_lib=-lstdc++
eduinowifi.menu.exception.disabled=Disabled (new can abort)
eduinowifi.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
eduinowifi.menu.exception.disabled=Disabled (new aborts on oom)
eduinowifi.menu.exception.disabled.build.exception_flags=-fno-exceptions
eduinowifi.menu.exception.disabled.build.stdcpp_lib=-lstdc++
eduinowifi.menu.exception.enabled=Enabled
eduinowifi.menu.exception.enabled.build.exception_flags=-fexceptions
@ -6904,11 +6808,8 @@ sonoff.menu.vt.heap=Heap
sonoff.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
sonoff.menu.vt.iram=IRAM
sonoff.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
sonoff.menu.exception.legacy=Legacy (new can return nullptr)
sonoff.menu.exception.legacy.build.exception_flags=-fno-exceptions
sonoff.menu.exception.legacy.build.stdcpp_lib=-lstdc++
sonoff.menu.exception.disabled=Disabled (new can abort)
sonoff.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
sonoff.menu.exception.disabled=Disabled (new aborts on oom)
sonoff.menu.exception.disabled.build.exception_flags=-fno-exceptions
sonoff.menu.exception.disabled.build.stdcpp_lib=-lstdc++
sonoff.menu.exception.enabled=Enabled
sonoff.menu.exception.enabled.build.exception_flags=-fexceptions
@ -7135,11 +7036,8 @@ espmxdevkit.menu.vt.heap=Heap
espmxdevkit.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espmxdevkit.menu.vt.iram=IRAM
espmxdevkit.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espmxdevkit.menu.exception.legacy=Legacy (new can return nullptr)
espmxdevkit.menu.exception.legacy.build.exception_flags=-fno-exceptions
espmxdevkit.menu.exception.legacy.build.stdcpp_lib=-lstdc++
espmxdevkit.menu.exception.disabled=Disabled (new can abort)
espmxdevkit.menu.exception.disabled.build.exception_flags=-fno-exceptions -DNEW_OOM_ABORT
espmxdevkit.menu.exception.disabled=Disabled (new aborts on oom)
espmxdevkit.menu.exception.disabled.build.exception_flags=-fno-exceptions
espmxdevkit.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espmxdevkit.menu.exception.enabled=Enabled
espmxdevkit.menu.exception.enabled.build.exception_flags=-fexceptions

View File

@ -740,17 +740,17 @@ String EspClass::getSketchMD5()
}
uint32_t lengthLeft = getSketchSize();
const size_t bufSize = 512;
std::unique_ptr<uint8_t[]> buf(new uint8_t[bufSize]);
std::unique_ptr<uint8_t[]> buf(new (std::nothrow) uint8_t[bufSize]);
uint32_t offset = 0;
if(!buf.get()) {
return String();
return emptyString;
}
MD5Builder md5;
md5.begin();
while( lengthLeft > 0) {
size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize;
if (!flashRead(offset, reinterpret_cast<uint32_t*>(buf.get()), (readBytes + 3) & ~3)) {
return String();
return emptyString;
}
md5.add(buf.get(), readBytes);
lengthLeft -= readBytes;

View File

@ -63,7 +63,7 @@ size_t Print::printf(const char *format, ...) {
size_t len = vsnprintf(temp, sizeof(temp), format, arg);
va_end(arg);
if (len > sizeof(temp) - 1) {
buffer = new char[len + 1];
buffer = new (std::nothrow) char[len + 1];
if (!buffer) {
return 0;
}
@ -86,7 +86,7 @@ size_t Print::printf_P(PGM_P format, ...) {
size_t len = vsnprintf_P(temp, sizeof(temp), format, arg);
va_end(arg);
if (len > sizeof(temp) - 1) {
buffer = new char[len + 1];
buffer = new (std::nothrow) char[len + 1];
if (!buffer) {
return 0;
}

View File

@ -32,18 +32,33 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
#if !defined(__cpp_exceptions) && !defined(NEW_OOM_ABORT)
void *operator new(size_t size)
#if !defined(__cpp_exceptions)
// overwrite weak operators new/new[] definitions
void* operator new(size_t size)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
__unhandled_exception(PSTR("OOM"));
}
return ret;
return ret;
}
void *operator new[](size_t size)
void* operator new[](size_t size)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
__unhandled_exception(PSTR("OOM"));
}
return ret;
}
void* operator new (size_t size, const std::nothrow_t&)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
@ -52,7 +67,18 @@ void *operator new[](size_t size)
}
return ret;
}
#endif // arduino's std::new legacy
void* operator new[] (size_t size, const std::nothrow_t&)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
return ret;
}
#endif // !defined(__cpp_exceptions)
void __cxa_pure_virtual(void)
{

View File

@ -18,6 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <new> // std::nothrow
#include "cbuf.h"
#include "c_types.h"
@ -43,7 +44,7 @@ size_t cbuf::resize(size_t newSize) {
return _size;
}
char *newbuf = new char[newSize];
char *newbuf = new (std::nothrow) char[newSize];
char *oldbuf = _buf;
if(!newbuf) {

View File

@ -36,35 +36,6 @@
#include <stddef.h> // size_t
#include <stdint.h>
#ifdef __cplusplus
namespace arduino
{
extern "C++"
template <typename T, typename ...TConstructorArgs>
T* new0 (size_t n, TConstructorArgs... TconstructorArgs)
{
// n==0: single allocation, otherwise it is an array
size_t offset = n? sizeof(size_t): 0;
size_t arraysize = n? n: 1;
T* ptr = (T*)malloc(offset + (arraysize * sizeof(T)));
if (ptr)
{
if (n)
*(size_t*)(ptr) = n;
for (size_t i = 0; i < arraysize; i++)
new (ptr + offset + i * sizeof(T)) T(TconstructorArgs...);
return ptr + offset;
}
return nullptr;
}
}
#define arduino_new(Type, ...) arduino::new0<Type>(0, ##__VA_ARGS__)
#define arduino_newarray(Type, n, ...) arduino::new0<Type>(n, ##__VA_ARGS__)
#endif // __cplusplus
#ifndef __STRINGIFY
#define __STRINGIFY(a) #a
#endif

View File

@ -220,6 +220,12 @@ void __wrap_system_restart_local() {
cut_here();
if (s_unhandled_exception && umm_last_fail_alloc_addr) {
// now outside from the "cut-here" zone, print correctly the `new` caller address,
// idf-monitor.py will be able to decode this one and show exact location in sources
ets_printf_P(PSTR("\nlast failed alloc caller: 0x%08x\n"), (uint32_t)umm_last_fail_alloc_addr);
}
custom_crash_callback( &rst_info, sp_dump + offset, stack_end );
ets_delay_us(10000);

View File

@ -22,6 +22,7 @@ void hexdump(const void *mem, uint32_t len, uint8_t cols);
extern "C" {
#endif
void __unhandled_exception(const char *str) __attribute__((noreturn));
void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn));
#define panic() __panic_func(PSTR(__FILE__), __LINE__, __func__)

View File

@ -323,36 +323,3 @@ C++
This assures correct behavior, including handling of all subobjects, which guarantees stability.
History: `#6269 <https://github.com/esp8266/Arduino/issues/6269>`__ `#6309 <https://github.com/esp8266/Arduino/pull/6309>`__ `#6312 <https://github.com/esp8266/Arduino/pull/6312>`__
- New optional allocator ``arduino_new``
A new optional global allocator is introduced with a different semantic:
- never throws exceptions on oom
- never calls constructors on oom
- returns nullptr on oom
It is similar to arduino ``new`` semantic without side effects
(except when parent constructors, or member constructors use ``new``).
Syntax is slightly different, the following shows the different usages:
.. code:: cpp
// with new:
SomeClass* sc = new SomeClass(arg1, arg2, ...);
delete sc;
SomeClass* scs = new SomeClass[42];
delete [] scs;
// with arduino_new:
SomeClass* sc = arduino_new(SomeClass, arg1, arg2, ...);
delete sc;
SomeClass* scs = arduino_newarray(SomeClass, 42);
delete [] scs;

View File

@ -178,8 +178,7 @@ void DNSServer::processNextRequest()
return;
std::unique_ptr<uint8_t[]> buffer(new (std::nothrow) uint8_t[currentPacketSize]);
if (buffer == NULL)
if (buffer == nullptr)
return;
_udp.read(buffer.get(), currentPacketSize);

View File

@ -182,7 +182,7 @@ bool HTTPClient::begin(String url, const uint8_t httpsFingerprint[20])
if (!beginInternal(url, "https")) {
return false;
}
_transportTraits = TransportTraitsPtr(new BearSSLTraits(httpsFingerprint));
_transportTraits = TransportTraitsPtr(new (std::nothrow) BearSSLTraits(httpsFingerprint));
if(!_transportTraits) {
DEBUG_HTTPCLIENT("[HTTP-Client][begin] could not create transport traits\n");
return false;

View File

@ -126,12 +126,12 @@ bool ESP8266WebServerTemplate<ServerType>::authenticate(const char * username, c
authReq = authReq.substring(6);
authReq.trim();
char toencodeLen = strlen(username)+strlen(password)+1;
char *toencode = new char[toencodeLen + 1];
char *toencode = new (std::nothrow) char[toencodeLen + 1];
if(toencode == NULL){
authReq = "";
return false;
}
char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
char *encoded = new (std::nothrow) char[base64_encode_expected_len(toencodeLen)+1];
if(encoded == NULL){
authReq = "";
delete[] toencode;

View File

@ -50,9 +50,13 @@ CertStore::CertInfo CertStore::_preprocessCert(uint32_t length, uint32_t offset,
memset(&ci, 0, sizeof(ci));
// Process it using SHA256, same as the hashed_dn
br_x509_decoder_context *ctx = new br_x509_decoder_context;
br_sha256_context *sha256 = new br_sha256_context;
br_x509_decoder_context *ctx = new (std::nothrow) br_x509_decoder_context;
br_sha256_context *sha256 = new (std::nothrow) br_sha256_context;
if (!ctx || !sha256) {
if (ctx)
delete ctx;
if (sha256)
delete sha256;
DEBUG_BSSL("CertStore::_preprocessCert: OOM\n");
return ci;
}
@ -202,7 +206,7 @@ const br_x509_trust_anchor *CertStore::findHashedTA(void *ctx, void *hashed_dn,
return nullptr;
}
data.close();
cs->_x509 = new X509List(der, ci.length);
cs->_x509 = new (std::nothrow) X509List(der, ci.length);
free(der);
if (!cs->_x509) {
DEBUG_BSSL("CertStore::findHashedTA: OOM\n");

View File

@ -977,7 +977,7 @@ extern "C" {
// Set custom list of ciphers
bool WiFiClientSecure::setCiphers(const uint16_t *cipherAry, int cipherCount) {
_cipher_list = nullptr;
_cipher_list = std::shared_ptr<uint16_t>(new uint16_t[cipherCount], std::default_delete<uint16_t[]>());
_cipher_list = std::shared_ptr<uint16_t>(new (std::nothrow) uint16_t[cipherCount], std::default_delete<uint16_t[]>());
if (!_cipher_list.get()) {
DEBUG_BSSL("setCiphers: list empty\n");
return false;
@ -1067,8 +1067,8 @@ bool WiFiClientSecure::_connectSSL(const char* hostName) {
_sc = std::make_shared<br_ssl_client_context>();
_eng = &_sc->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
if (!_sc || !_iobuf_in || !_iobuf_out) {
_freeSSL(); // Frees _sc, _iobuf*
@ -1183,8 +1183,8 @@ bool WiFiClientSecure::_connectSSLServerRSA(const X509List *chain,
_oom_err = false;
_sc_svr = std::make_shared<br_ssl_server_context>();
_eng = &_sc_svr->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
if (!_sc_svr || !_iobuf_in || !_iobuf_out) {
_freeSSL();
@ -1220,8 +1220,8 @@ bool WiFiClientSecure::_connectSSLServerEC(const X509List *chain,
_oom_err = false;
_sc_svr = std::make_shared<br_ssl_server_context>();
_eng = &_sc_svr->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
if (!_sc_svr || !_iobuf_in || !_iobuf_out) {
_freeSSL();
@ -1421,7 +1421,7 @@ bool WiFiClientSecure::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint1
default: return false; // Invalid size
}
int ttlLen = sizeof(clientHelloHead_P) + (2 + sizeof(suites_P)) + (sizeof(clientHelloTail_P) + 1);
uint8_t *clientHello = new uint8_t[ttlLen];
uint8_t *clientHello = new (std::nothrow) uint8_t[ttlLen];
if (!clientHello) {
DEBUG_BSSL("probeMaxFragmentLength: OOM\n");
return false;

View File

@ -1,159 +0,0 @@
// show arduino_new benefits
// released to public domain
// result is below
class SomeClass {
public:
SomeClass(const String& s1 = emptyString, const String& s2 = emptyString) {
Serial.printf("SomeClass@%p(%s)(%s)\n", this, s1.c_str(), s2.c_str());
}
~SomeClass() {
Serial.printf("~ SomeClass @%p\n", this);
}
};
class oom {
private:
char large [65000];
public:
oom() {
Serial.printf("this constructor should not be called\n");
}
};
void setup() {
Serial.begin(115200);
Serial.printf("\n\narduino_new benefits\n\n");
delay(5000); // avoid too frequent bootloop
// arduino_new / arduino_newarray api
Serial.printf("\n----- arduino_new:\n");
auto an = arduino_new(SomeClass);
delete an;
Serial.printf("\n----- arduino_new with oom:\n");
auto anoom = arduino_new(oom);
Serial.printf("nullptr: %p\n", anoom);
delete anoom;
Serial.printf("\n----- arduino_new with constructor parameters:\n");
auto ancp = arduino_new(SomeClass, "param1", "param2");
delete ancp;
Serial.printf("\n----- arduino_newarray[2]\n");
auto ana2 = arduino_newarray(SomeClass, 2);
Serial.printf("@:%p s=%zd s(2)=%zd\n", ana2, sizeof(SomeClass), sizeof(SomeClass[2]));
Serial.printf("0: %p\n", &ana2[0]);
Serial.printf("1: %p\n", &ana2[1]);
delete [] ana2;
Serial.printf("\n----- arduino_newarray[2] (with constructor parameters)\n");
auto ana2cp = arduino_newarray(SomeClass, 2, "param1");
Serial.printf("@:%p s=%zd s(2)=%zd\n", ana2cp, sizeof(SomeClass), sizeof(SomeClass[2]));
Serial.printf("0: %p\n", &ana2cp[0]);
Serial.printf("1: %p\n", &ana2cp[1]);
delete [] ana2cp;
Serial.printf("\n----- arduino_newarray[100000]\n");
auto anaX = arduino_newarray(SomeClass, 100000);
Serial.printf("@:%p\n", anaX);
// standard c++ api for new and new[]
Serial.printf("\n----- new\n");
auto sn = new SomeClass;
delete sn;
Serial.printf("\n----- new with oom: (abort() with option 'Exceptions: Disabled (new can abort)'\n");
auto snoom = new oom;
Serial.printf("nullptr: %p\n", snoom);
delete snoom;
Serial.printf("\n----- new[2]\n");
auto sna2 = new SomeClass[2];
Serial.printf("@:%p s=%zd s(2)=%zd\n", sna2, sizeof(SomeClass), sizeof(SomeClass[2]));
Serial.printf("0: %p\n", &sna2[0]);
Serial.printf("1: %p\n", &sna2[1]);
delete [] sna2;
Serial.printf("\n----- new[10000] (badly fails with 'Exceptions: Legacy' or '...Disabled'\n");
auto snaX = new SomeClass[100000];
Serial.printf("@:%p\n", snaX);
}
void loop() {
}
//////////////////////////////
/*
Result with:
Exceptions: Legacy(new can return nullptr)
//////////////////////////////
arduino_new benefits
----- arduino_new:
SomeClass@0x3fff1864()()
~ SomeClass @0x3fff1864
----- arduino_new with oom:
nullptr: 0
----- arduino_new with constructor parameters:
SomeClass@0x3fff1864(param1)(param2)
~ SomeClass @0x3fff1864
----- arduino_newarray[2]
SomeClass@0x3fff1868()()
SomeClass@0x3fff1869()()
@: 0x3fff1868 s = 1 s(2) = 2
0: 0x3fff1868
1: 0x3fff1869
~ SomeClass @0x3fff1869
~ SomeClass @0x3fff1868
----- arduino_newarray[2](with constructor parameters)
SomeClass@0x3fff1868(param1)()
SomeClass@0x3fff1869(param1)()
@: 0x3fff1868 s = 1 s(2) = 2
0: 0x3fff1868
1: 0x3fff1869
~ SomeClass @0x3fff1869
~ SomeClass @0x3fff1868
----- arduino_newarray[100000]
@: 0
----- new
SomeClass@0x3fff1864()()
~ SomeClass @0x3fff1864
----- new with oom: (abort() with option 'Exceptions: Disabled (new can abort)'
this constructor should not be called
nullptr: 0
----- new[2]
SomeClass@0x3fff1868()()
SomeClass@0x3fff1869()()
@:0x3fff1868 s = 1 s(2) = 2
0: 0x3fff1868
1: 0x3fff1869
~ SomeClass @0x3fff1869
~ SomeClass @0x3fff1868
----- new[10000](badly fails with 'Exceptions: Legacy' or '...Disabled'
Exception(29):
epc1 = 0x402013de epc2 = 0x00000000 epc3 = 0x00000000 excvaddr = 0x00000000 depc = 0x00000000
>>> stack >>>
...
*/
/////////////////////////////

View File

@ -995,11 +995,8 @@ macros = {
]),
'exception_menu': collections.OrderedDict([
( '.menu.exception.legacy', 'Legacy (new can return nullptr)' ),
( '.menu.exception.legacy.build.exception_flags', '-fno-exceptions' ),
( '.menu.exception.legacy.build.stdcpp_lib', '-lstdc++' ),
( '.menu.exception.disabled', 'Disabled (new can abort)' ),
( '.menu.exception.disabled.build.exception_flags', '-fno-exceptions -DNEW_OOM_ABORT' ),
( '.menu.exception.disabled', 'Disabled (new aborts on oom)' ),
( '.menu.exception.disabled.build.exception_flags', '-fno-exceptions' ),
( '.menu.exception.disabled.build.stdcpp_lib', '-lstdc++' ),
( '.menu.exception.enabled', 'Enabled' ),
( '.menu.exception.enabled.build.exception_flags', '-fexceptions' ),