diff options
-rw-r--r-- | src/memory.cc | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/memory.cc b/src/memory.cc index 0c4ad3b..8e5574a 100644 --- a/src/memory.cc +++ b/src/memory.cc @@ -7,11 +7,30 @@ #include <malloc.h> #include "stdexcept.h" +namespace std { + void terminate(); +} + +typedef void (*new_handler)(); +static new_handler new_handl = &std::terminate; + + +namespace std { + new_handler set_new_handler(new_handler handl) { + new_handler old = new_handl; + new_handl = handl; + return old; + } +} + + __attribute__((weak)) void * operator new(size_t size) { + void * mem = malloc(size); - if(mem == NULL) { - throw std::bad_alloc(); + while(mem == NULL) { + new_handl(); + mem = malloc(size); } return mem; |