mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-10-31 15:50:55 +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:
		
				
					committed by
					
						 david gauchard
						david gauchard
					
				
			
			
				
	
			
			
			
						parent
						
							5d5cd1d426
						
					
				
				
					commit
					82a1382864
				
			| @@ -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(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user