@@ -32,18 +32,33 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
3232extern " C" void __cxa_deleted_virtual (void ) __attribute__ ((__noreturn__));
3333
3434
35- #if !defined(__cpp_exceptions) && !defined(NEW_OOM_ABORT)
36- void *operator new (size_t size)
35+ #if !defined(__cpp_exceptions)
36+
37+ // overwrite weak operators new/new[] definitions
38+
39+ void * operator new (size_t size)
40+ {
41+ void *ret = malloc (size);
42+ if (0 != size && 0 == ret) {
43+ umm_last_fail_alloc_addr = __builtin_return_address (0 );
44+ umm_last_fail_alloc_size = size;
45+ __unhandled_exception (PSTR (" OOM" ));
46+ }
47+ return ret;
48+ }
49+
50+ void * operator new [](size_t size)
3751{
3852 void *ret = malloc (size);
3953 if (0 != size && 0 == ret) {
4054 umm_last_fail_alloc_addr = __builtin_return_address (0 );
4155 umm_last_fail_alloc_size = size;
56+ __unhandled_exception (PSTR (" OOM" ));
4257 }
43- return ret;
58+ return ret;
4459}
4560
46- void * operator new [] (size_t size)
61+ void * operator new (size_t size, const std:: nothrow_t & )
4762{
4863 void *ret = malloc (size);
4964 if (0 != size && 0 == ret) {
@@ -52,7 +67,18 @@ void *operator new[](size_t size)
5267 }
5368 return ret;
5469}
55- #endif // arduino's std::new legacy
70+
71+ void * operator new [] (size_t size, const std::nothrow_t &)
72+ {
73+ void *ret = malloc (size);
74+ if (0 != size && 0 == ret) {
75+ umm_last_fail_alloc_addr = __builtin_return_address (0 );
76+ umm_last_fail_alloc_size = size;
77+ }
78+ return ret;
79+ }
80+
81+ #endif // !defined(__cpp_exceptions)
5682
5783void __cxa_pure_virtual (void )
5884{
0 commit comments