Skip to content

Commit fba3f5c

Browse files
Don't throw exceptions from operator new by default
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 esp8266#6309
1 parent 29bedfa commit fba3f5c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

cores/esp8266/abi.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@ extern int umm_last_fail_alloc_size;
3131
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
3232
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
3333

34+
35+
#ifndef __cpp_exceptions
36+
void *operator new(size_t size)
37+
{
38+
void *ret = malloc(size);
39+
if (0 != size && 0 == ret) {
40+
umm_last_fail_alloc_addr = __builtin_return_address(0);
41+
umm_last_fail_alloc_size = size;
42+
}
43+
return ret;
44+
}
45+
46+
void *operator new[](size_t size)
47+
{
48+
void *ret = malloc(size);
49+
if (0 != size && 0 == ret) {
50+
umm_last_fail_alloc_addr = __builtin_return_address(0);
51+
umm_last_fail_alloc_size = size;
52+
}
53+
return ret;
54+
}
55+
#endif
56+
3457
void __cxa_pure_virtual(void)
3558
{
3659
panic();

0 commit comments

Comments
 (0)