1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-04 18:03:20 +03:00

exceptions: optionally enforce c++ standards (#6333)

* exceptions: 3 choices: legacy, std::new never returns 0, or exceptions enabled
* arduino_new (doc, example, array)
This commit is contained in:
david gauchard 2019-08-29 00:21:10 +02:00 committed by GitHub
parent 0a031ce957
commit 85f1ea7c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 420 additions and 65 deletions

View File

@ -48,8 +48,11 @@ generic.menu.vt.heap=Heap
generic.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM generic.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
generic.menu.vt.iram=IRAM generic.menu.vt.iram=IRAM
generic.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM generic.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
generic.menu.exception.disabled=Disabled generic.menu.exception.legacy=Legacy (new can return nullptr)
generic.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ generic.menu.exception.disabled.build.stdcpp_lib=-lstdc++
generic.menu.exception.enabled=Enabled generic.menu.exception.enabled=Enabled
generic.menu.exception.enabled.build.exception_flags=-fexceptions generic.menu.exception.enabled.build.exception_flags=-fexceptions
@ -510,8 +513,11 @@ esp8285.menu.vt.heap=Heap
esp8285.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM esp8285.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
esp8285.menu.vt.iram=IRAM esp8285.menu.vt.iram=IRAM
esp8285.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM esp8285.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
esp8285.menu.exception.disabled=Disabled esp8285.menu.exception.legacy=Legacy (new can return nullptr)
esp8285.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ esp8285.menu.exception.disabled.build.stdcpp_lib=-lstdc++
esp8285.menu.exception.enabled=Enabled esp8285.menu.exception.enabled=Enabled
esp8285.menu.exception.enabled.build.exception_flags=-fexceptions esp8285.menu.exception.enabled.build.exception_flags=-fexceptions
@ -791,8 +797,11 @@ espduino.menu.vt.heap=Heap
espduino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM espduino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espduino.menu.vt.iram=IRAM espduino.menu.vt.iram=IRAM
espduino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM espduino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espduino.menu.exception.disabled=Disabled espduino.menu.exception.legacy=Legacy (new can return nullptr)
espduino.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ espduino.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espduino.menu.exception.enabled=Enabled espduino.menu.exception.enabled=Enabled
espduino.menu.exception.enabled.build.exception_flags=-fexceptions espduino.menu.exception.enabled.build.exception_flags=-fexceptions
@ -978,8 +987,11 @@ huzzah.menu.vt.heap=Heap
huzzah.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM huzzah.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
huzzah.menu.vt.iram=IRAM huzzah.menu.vt.iram=IRAM
huzzah.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM huzzah.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
huzzah.menu.exception.disabled=Disabled huzzah.menu.exception.legacy=Legacy (new can return nullptr)
huzzah.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ huzzah.menu.exception.disabled.build.stdcpp_lib=-lstdc++
huzzah.menu.exception.enabled=Enabled huzzah.menu.exception.enabled=Enabled
huzzah.menu.exception.enabled.build.exception_flags=-fexceptions huzzah.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1166,8 +1178,11 @@ inventone.menu.vt.heap=Heap
inventone.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM inventone.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
inventone.menu.vt.iram=IRAM inventone.menu.vt.iram=IRAM
inventone.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM inventone.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
inventone.menu.exception.disabled=Disabled inventone.menu.exception.legacy=Legacy (new can return nullptr)
inventone.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ inventone.menu.exception.disabled.build.stdcpp_lib=-lstdc++
inventone.menu.exception.enabled=Enabled inventone.menu.exception.enabled=Enabled
inventone.menu.exception.enabled.build.exception_flags=-fexceptions inventone.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1354,8 +1369,11 @@ cw01.menu.vt.heap=Heap
cw01.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM cw01.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
cw01.menu.vt.iram=IRAM cw01.menu.vt.iram=IRAM
cw01.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM cw01.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
cw01.menu.exception.disabled=Disabled cw01.menu.exception.legacy=Legacy (new can return nullptr)
cw01.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ cw01.menu.exception.disabled.build.stdcpp_lib=-lstdc++
cw01.menu.exception.enabled=Enabled cw01.menu.exception.enabled=Enabled
cw01.menu.exception.enabled.build.exception_flags=-fexceptions cw01.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1545,8 +1563,11 @@ espresso_lite_v1.menu.vt.heap=Heap
espresso_lite_v1.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM 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=IRAM
espresso_lite_v1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM espresso_lite_v1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espresso_lite_v1.menu.exception.disabled=Disabled espresso_lite_v1.menu.exception.legacy=Legacy (new can return nullptr)
espresso_lite_v1.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ espresso_lite_v1.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espresso_lite_v1.menu.exception.enabled=Enabled espresso_lite_v1.menu.exception.enabled=Enabled
espresso_lite_v1.menu.exception.enabled.build.exception_flags=-fexceptions espresso_lite_v1.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1736,8 +1757,11 @@ espresso_lite_v2.menu.vt.heap=Heap
espresso_lite_v2.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM 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=IRAM
espresso_lite_v2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM espresso_lite_v2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espresso_lite_v2.menu.exception.disabled=Disabled espresso_lite_v2.menu.exception.legacy=Legacy (new can return nullptr)
espresso_lite_v2.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ espresso_lite_v2.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espresso_lite_v2.menu.exception.enabled=Enabled espresso_lite_v2.menu.exception.enabled=Enabled
espresso_lite_v2.menu.exception.enabled.build.exception_flags=-fexceptions espresso_lite_v2.menu.exception.enabled.build.exception_flags=-fexceptions
@ -1927,8 +1951,11 @@ phoenix_v1.menu.vt.heap=Heap
phoenix_v1.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM phoenix_v1.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
phoenix_v1.menu.vt.iram=IRAM phoenix_v1.menu.vt.iram=IRAM
phoenix_v1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM phoenix_v1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
phoenix_v1.menu.exception.disabled=Disabled phoenix_v1.menu.exception.legacy=Legacy (new can return nullptr)
phoenix_v1.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ phoenix_v1.menu.exception.disabled.build.stdcpp_lib=-lstdc++
phoenix_v1.menu.exception.enabled=Enabled phoenix_v1.menu.exception.enabled=Enabled
phoenix_v1.menu.exception.enabled.build.exception_flags=-fexceptions phoenix_v1.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2118,8 +2145,11 @@ phoenix_v2.menu.vt.heap=Heap
phoenix_v2.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM phoenix_v2.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
phoenix_v2.menu.vt.iram=IRAM phoenix_v2.menu.vt.iram=IRAM
phoenix_v2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM phoenix_v2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
phoenix_v2.menu.exception.disabled=Disabled phoenix_v2.menu.exception.legacy=Legacy (new can return nullptr)
phoenix_v2.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ phoenix_v2.menu.exception.disabled.build.stdcpp_lib=-lstdc++
phoenix_v2.menu.exception.enabled=Enabled phoenix_v2.menu.exception.enabled=Enabled
phoenix_v2.menu.exception.enabled.build.exception_flags=-fexceptions phoenix_v2.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2309,8 +2339,11 @@ nodemcu.menu.vt.heap=Heap
nodemcu.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM nodemcu.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
nodemcu.menu.vt.iram=IRAM nodemcu.menu.vt.iram=IRAM
nodemcu.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM nodemcu.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
nodemcu.menu.exception.disabled=Disabled nodemcu.menu.exception.legacy=Legacy (new can return nullptr)
nodemcu.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ nodemcu.menu.exception.disabled.build.stdcpp_lib=-lstdc++
nodemcu.menu.exception.enabled=Enabled nodemcu.menu.exception.enabled=Enabled
nodemcu.menu.exception.enabled.build.exception_flags=-fexceptions nodemcu.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2497,8 +2530,11 @@ nodemcuv2.menu.vt.heap=Heap
nodemcuv2.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM nodemcuv2.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
nodemcuv2.menu.vt.iram=IRAM nodemcuv2.menu.vt.iram=IRAM
nodemcuv2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM nodemcuv2.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
nodemcuv2.menu.exception.disabled=Disabled nodemcuv2.menu.exception.legacy=Legacy (new can return nullptr)
nodemcuv2.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ nodemcuv2.menu.exception.disabled.build.stdcpp_lib=-lstdc++
nodemcuv2.menu.exception.enabled=Enabled nodemcuv2.menu.exception.enabled=Enabled
nodemcuv2.menu.exception.enabled.build.exception_flags=-fexceptions nodemcuv2.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2685,8 +2721,11 @@ modwifi.menu.vt.heap=Heap
modwifi.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM modwifi.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
modwifi.menu.vt.iram=IRAM modwifi.menu.vt.iram=IRAM
modwifi.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM modwifi.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
modwifi.menu.exception.disabled=Disabled modwifi.menu.exception.legacy=Legacy (new can return nullptr)
modwifi.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ modwifi.menu.exception.disabled.build.stdcpp_lib=-lstdc++
modwifi.menu.exception.enabled=Enabled modwifi.menu.exception.enabled=Enabled
modwifi.menu.exception.enabled.build.exception_flags=-fexceptions modwifi.menu.exception.enabled.build.exception_flags=-fexceptions
@ -2893,8 +2932,11 @@ thing.menu.vt.heap=Heap
thing.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM thing.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
thing.menu.vt.iram=IRAM thing.menu.vt.iram=IRAM
thing.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM thing.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
thing.menu.exception.disabled=Disabled thing.menu.exception.legacy=Legacy (new can return nullptr)
thing.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ thing.menu.exception.disabled.build.stdcpp_lib=-lstdc++
thing.menu.exception.enabled=Enabled thing.menu.exception.enabled=Enabled
thing.menu.exception.enabled.build.exception_flags=-fexceptions thing.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3081,8 +3123,11 @@ thingdev.menu.vt.heap=Heap
thingdev.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM thingdev.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
thingdev.menu.vt.iram=IRAM thingdev.menu.vt.iram=IRAM
thingdev.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM thingdev.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
thingdev.menu.exception.disabled=Disabled thingdev.menu.exception.legacy=Legacy (new can return nullptr)
thingdev.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ thingdev.menu.exception.disabled.build.stdcpp_lib=-lstdc++
thingdev.menu.exception.enabled=Enabled thingdev.menu.exception.enabled=Enabled
thingdev.menu.exception.enabled.build.exception_flags=-fexceptions thingdev.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3269,8 +3314,11 @@ esp210.menu.vt.heap=Heap
esp210.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM esp210.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
esp210.menu.vt.iram=IRAM esp210.menu.vt.iram=IRAM
esp210.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM esp210.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
esp210.menu.exception.disabled=Disabled esp210.menu.exception.legacy=Legacy (new can return nullptr)
esp210.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ esp210.menu.exception.disabled.build.stdcpp_lib=-lstdc++
esp210.menu.exception.enabled=Enabled esp210.menu.exception.enabled=Enabled
esp210.menu.exception.enabled.build.exception_flags=-fexceptions esp210.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3457,8 +3505,11 @@ d1_mini.menu.vt.heap=Heap
d1_mini.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM d1_mini.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
d1_mini.menu.vt.iram=IRAM d1_mini.menu.vt.iram=IRAM
d1_mini.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM d1_mini.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
d1_mini.menu.exception.disabled=Disabled d1_mini.menu.exception.legacy=Legacy (new can return nullptr)
d1_mini.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ d1_mini.menu.exception.disabled.build.stdcpp_lib=-lstdc++
d1_mini.menu.exception.enabled=Enabled d1_mini.menu.exception.enabled=Enabled
d1_mini.menu.exception.enabled.build.exception_flags=-fexceptions d1_mini.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3645,8 +3696,11 @@ d1_mini_pro.menu.vt.heap=Heap
d1_mini_pro.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM 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=IRAM
d1_mini_pro.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM d1_mini_pro.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
d1_mini_pro.menu.exception.disabled=Disabled d1_mini_pro.menu.exception.legacy=Legacy (new can return nullptr)
d1_mini_pro.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ d1_mini_pro.menu.exception.disabled.build.stdcpp_lib=-lstdc++
d1_mini_pro.menu.exception.enabled=Enabled d1_mini_pro.menu.exception.enabled=Enabled
d1_mini_pro.menu.exception.enabled.build.exception_flags=-fexceptions d1_mini_pro.menu.exception.enabled.build.exception_flags=-fexceptions
@ -3816,8 +3870,11 @@ d1_mini_lite.menu.vt.heap=Heap
d1_mini_lite.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM 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=IRAM
d1_mini_lite.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM d1_mini_lite.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
d1_mini_lite.menu.exception.disabled=Disabled d1_mini_lite.menu.exception.legacy=Legacy (new can return nullptr)
d1_mini_lite.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ d1_mini_lite.menu.exception.disabled.build.stdcpp_lib=-lstdc++
d1_mini_lite.menu.exception.enabled=Enabled d1_mini_lite.menu.exception.enabled=Enabled
d1_mini_lite.menu.exception.enabled.build.exception_flags=-fexceptions d1_mini_lite.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4044,8 +4101,11 @@ d1.menu.vt.heap=Heap
d1.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM d1.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
d1.menu.vt.iram=IRAM d1.menu.vt.iram=IRAM
d1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM d1.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
d1.menu.exception.disabled=Disabled d1.menu.exception.legacy=Legacy (new can return nullptr)
d1.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ d1.menu.exception.disabled.build.stdcpp_lib=-lstdc++
d1.menu.exception.enabled=Enabled d1.menu.exception.enabled=Enabled
d1.menu.exception.enabled.build.exception_flags=-fexceptions d1.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4232,8 +4292,11 @@ espino.menu.vt.heap=Heap
espino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM espino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espino.menu.vt.iram=IRAM espino.menu.vt.iram=IRAM
espino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM espino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espino.menu.exception.disabled=Disabled espino.menu.exception.legacy=Legacy (new can return nullptr)
espino.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ espino.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espino.menu.exception.enabled=Enabled espino.menu.exception.enabled=Enabled
espino.menu.exception.enabled.build.exception_flags=-fexceptions espino.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4423,8 +4486,11 @@ espinotee.menu.vt.heap=Heap
espinotee.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM espinotee.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espinotee.menu.vt.iram=IRAM espinotee.menu.vt.iram=IRAM
espinotee.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM espinotee.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espinotee.menu.exception.disabled=Disabled espinotee.menu.exception.legacy=Legacy (new can return nullptr)
espinotee.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ espinotee.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espinotee.menu.exception.enabled=Enabled espinotee.menu.exception.enabled=Enabled
espinotee.menu.exception.enabled.build.exception_flags=-fexceptions espinotee.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4628,8 +4694,11 @@ wifinfo.menu.vt.heap=Heap
wifinfo.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM wifinfo.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
wifinfo.menu.vt.iram=IRAM wifinfo.menu.vt.iram=IRAM
wifinfo.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM wifinfo.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
wifinfo.menu.exception.disabled=Disabled wifinfo.menu.exception.legacy=Legacy (new can return nullptr)
wifinfo.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ wifinfo.menu.exception.disabled.build.stdcpp_lib=-lstdc++
wifinfo.menu.exception.enabled=Enabled wifinfo.menu.exception.enabled=Enabled
wifinfo.menu.exception.enabled.build.exception_flags=-fexceptions wifinfo.menu.exception.enabled.build.exception_flags=-fexceptions
@ -4871,8 +4940,11 @@ arduino-esp8266.menu.vt.heap=Heap
arduino-esp8266.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM arduino-esp8266.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
arduino-esp8266.menu.vt.iram=IRAM arduino-esp8266.menu.vt.iram=IRAM
arduino-esp8266.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM arduino-esp8266.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
arduino-esp8266.menu.exception.disabled=Disabled arduino-esp8266.menu.exception.legacy=Legacy (new can return nullptr)
arduino-esp8266.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ arduino-esp8266.menu.exception.disabled.build.stdcpp_lib=-lstdc++
arduino-esp8266.menu.exception.enabled=Enabled arduino-esp8266.menu.exception.enabled=Enabled
arduino-esp8266.menu.exception.enabled.build.exception_flags=-fexceptions arduino-esp8266.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5060,8 +5132,11 @@ gen4iod.menu.vt.heap=Heap
gen4iod.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM gen4iod.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
gen4iod.menu.vt.iram=IRAM gen4iod.menu.vt.iram=IRAM
gen4iod.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM gen4iod.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
gen4iod.menu.exception.disabled=Disabled gen4iod.menu.exception.legacy=Legacy (new can return nullptr)
gen4iod.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ gen4iod.menu.exception.disabled.build.stdcpp_lib=-lstdc++
gen4iod.menu.exception.enabled=Enabled gen4iod.menu.exception.enabled=Enabled
gen4iod.menu.exception.enabled.build.exception_flags=-fexceptions gen4iod.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5249,8 +5324,11 @@ oak.menu.vt.heap=Heap
oak.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM oak.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
oak.menu.vt.iram=IRAM oak.menu.vt.iram=IRAM
oak.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM oak.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
oak.menu.exception.disabled=Disabled oak.menu.exception.legacy=Legacy (new can return nullptr)
oak.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ oak.menu.exception.disabled.build.stdcpp_lib=-lstdc++
oak.menu.exception.enabled=Enabled oak.menu.exception.enabled=Enabled
oak.menu.exception.enabled.build.exception_flags=-fexceptions oak.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5437,8 +5515,11 @@ wifiduino.menu.vt.heap=Heap
wifiduino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM wifiduino.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
wifiduino.menu.vt.iram=IRAM wifiduino.menu.vt.iram=IRAM
wifiduino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM wifiduino.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
wifiduino.menu.exception.disabled=Disabled wifiduino.menu.exception.legacy=Legacy (new can return nullptr)
wifiduino.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ wifiduino.menu.exception.disabled.build.stdcpp_lib=-lstdc++
wifiduino.menu.exception.enabled=Enabled wifiduino.menu.exception.enabled=Enabled
wifiduino.menu.exception.enabled.build.exception_flags=-fexceptions wifiduino.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5625,8 +5706,11 @@ wifi_slot.menu.vt.heap=Heap
wifi_slot.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM wifi_slot.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
wifi_slot.menu.vt.iram=IRAM wifi_slot.menu.vt.iram=IRAM
wifi_slot.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM wifi_slot.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
wifi_slot.menu.exception.disabled=Disabled wifi_slot.menu.exception.legacy=Legacy (new can return nullptr)
wifi_slot.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ wifi_slot.menu.exception.disabled.build.stdcpp_lib=-lstdc++
wifi_slot.menu.exception.enabled=Enabled wifi_slot.menu.exception.enabled=Enabled
wifi_slot.menu.exception.enabled.build.exception_flags=-fexceptions wifi_slot.menu.exception.enabled.build.exception_flags=-fexceptions
@ -5923,8 +6007,11 @@ wiolink.menu.vt.heap=Heap
wiolink.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM wiolink.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
wiolink.menu.vt.iram=IRAM wiolink.menu.vt.iram=IRAM
wiolink.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM wiolink.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
wiolink.menu.exception.disabled=Disabled wiolink.menu.exception.legacy=Legacy (new can return nullptr)
wiolink.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ wiolink.menu.exception.disabled.build.stdcpp_lib=-lstdc++
wiolink.menu.exception.enabled=Enabled wiolink.menu.exception.enabled=Enabled
wiolink.menu.exception.enabled.build.exception_flags=-fexceptions wiolink.menu.exception.enabled.build.exception_flags=-fexceptions
@ -6111,8 +6198,11 @@ espectro.menu.vt.heap=Heap
espectro.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM espectro.menu.vt.heap.build.vtable_flags=-DVTABLES_IN_DRAM
espectro.menu.vt.iram=IRAM espectro.menu.vt.iram=IRAM
espectro.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM espectro.menu.vt.iram.build.vtable_flags=-DVTABLES_IN_IRAM
espectro.menu.exception.disabled=Disabled espectro.menu.exception.legacy=Legacy (new can return nullptr)
espectro.menu.exception.disabled.build.exception_flags=-fno-exceptions 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.build.stdcpp_lib=-lstdc++ espectro.menu.exception.disabled.build.stdcpp_lib=-lstdc++
espectro.menu.exception.enabled=Enabled espectro.menu.exception.enabled=Enabled
espectro.menu.exception.enabled.build.exception_flags=-fexceptions espectro.menu.exception.enabled.build.exception_flags=-fexceptions

View File

@ -32,7 +32,7 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__)); extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
#ifndef __cpp_exceptions #if !defined(__cpp_exceptions) && !defined(NEW_OOM_ABORT)
void *operator new(size_t size) void *operator new(size_t size)
{ {
void *ret = malloc(size); void *ret = malloc(size);
@ -52,7 +52,7 @@ void *operator new[](size_t size)
} }
return ret; return ret;
} }
#endif #endif // arduino's std::new legacy
void __cxa_pure_virtual(void) void __cxa_pure_virtual(void)
{ {

View File

@ -32,6 +32,37 @@
#define WIFI_HAS_EVENT_CALLBACK #define WIFI_HAS_EVENT_CALLBACK
#ifdef __cplusplus
#include <stdlib.h> // malloc()
#include <stddef.h> // size_t
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 #ifndef __STRINGIFY
#define __STRINGIFY(a) #a #define __STRINGIFY(a) #a
@ -61,4 +92,4 @@ inline uint32_t esp_get_cycle_count() {
} }
#endif // not CORE_MOCK #endif // not CORE_MOCK
#endif #endif // CORE_ESP8266_FEATURES_H

View File

@ -215,3 +215,75 @@ using FPSTR would become...
String response2; String response2;
response2 += FPSTR(HTTP); response2 += FPSTR(HTTP);
} }
C++
----
- About C++ exceptions, ``operator new``, and Exceptions menu option
The C++ standard says the following about the ``new`` operator behavior when encountering heap shortage (memory full):
- has to throw a ``std::bad_alloc`` C++ exception when they are enabled
- will ``abort()`` otherwise
There are several reasons for the first point above, among which are:
- guarantee that the return of new is never a ``nullptr``
- guarantee full construction of the top level object plus all member subobjects
- guarantee that any subobjects partially constructed get destroyed, and in the correct order, if oom is encountered midway through construction
When C++ exceptions are disabled, or when using ``new(nothrow)``, the above guarantees can't be upheld, so the second point (``abort()``) above is the only ``std::c++`` viable solution.
Historically in Arduino environments, ``new`` is overloaded to simply return the equivalent ``malloc()`` which in turn can return ``nullptr``.
This behavior is not C++ standard, and there is good reason for that: there are hidden and very bad side effects. The *class and member constructors are always called, even when memory is full* (``this == nullptr``).
In addition, the memory allocation for the top object could succeed, but allocation required for some member object could fail, leaving construction in an undefined state.
So the historical behavior of Ardudino's ``new``, when faced with insufficient memory, will lead to bad crashes sooner or later, sometimes unexplainable, generally due to memory corruption even when the returned value is checked and managed.
Luckily on esp8266, trying to update RAM near address 0 will immediately raise an hardware exception, unlike on other uC like avr on which that memory can be accessible.
As of core 2.6.0, there are 3 options: legacy (default) and two clear cases when ``new`` encounters oom:
- ``new`` returns ``nullptr``, with possible bad effects or immediate crash when constructors (called anyway) initialize members (exceptions are disabled in this case)
- C++ exceptions are disabled: ``new`` calls ``abort()`` and will "cleanly" crash, because there is no way to honor memory allocation or to recover gracefully.
- C++ exceptions are enabled: ``new`` throws a ``std::bad_alloc`` C++ exception, which can be caught and handled gracefully.
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

@ -0,0 +1,159 @@
// 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

@ -883,8 +883,11 @@ macros = {
]), ]),
'exception_menu': collections.OrderedDict([ 'exception_menu': collections.OrderedDict([
( '.menu.exception.disabled', 'Disabled' ), ( '.menu.exception.legacy', 'Legacy (new can return nullptr)' ),
( '.menu.exception.disabled.build.exception_flags', '-fno-exceptions' ), ( '.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.build.stdcpp_lib', '-lstdc++' ), ( '.menu.exception.disabled.build.stdcpp_lib', '-lstdc++' ),
( '.menu.exception.enabled', 'Enabled' ), ( '.menu.exception.enabled', 'Enabled' ),
( '.menu.exception.enabled.build.exception_flags', '-fexceptions' ), ( '.menu.exception.enabled.build.exception_flags', '-fexceptions' ),