1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-16 00:43:00 +03:00

Don't throw exceptions from operator new by default (#6312)

Default mode (no exceptions) will no longer use the stdc++ library new
allocator when there is not enough memory.  Instead, it will return
nullptr.  This is the pre-exceptions-available behavior (2.5.0 and
earlier).

When exceptions are enabled, use the real new and throw exceptions that
can be caught at higher levels, or which will crash the app with an
uncaught exception if they're not handled.

Update to #6309
This commit is contained in:
Earle F. Philhower, III
2019-07-23 01:18:52 -07:00
committed by david gauchard
parent 5d5cd1d426
commit 82a1382864

View File

@ -31,6 +31,29 @@ extern int umm_last_fail_alloc_size;
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
#ifndef __cpp_exceptions
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;
}
return ret;
}
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;
}
return ret;
}
#endif
void __cxa_pure_virtual(void)
{
panic();