| 1 | #include <new> |
| 2 | #include <exception_defines.h> |
| 3 | |
| 4 | using std::bad_alloc; |
| 5 | |
| 6 | extern "C" void *malloc (std::size_t); |
| 7 | extern "C" void abort (void); |
| 8 | |
| 9 | void * |
| 10 | operator new (std::size_t sz, const std::nothrow_t&) throw() |
| 11 | { |
| 12 | void *p; |
| 13 | |
| 14 | /* malloc (0) is unpredictable; avoid it. */ |
| 15 | if (sz == 0) |
| 16 | sz = 1; |
| 17 | p = (void *) malloc (sz); |
| 18 | return p; |
| 19 | } |
| 20 | |
| 21 | void * |
| 22 | operator new (std::size_t sz) throw (std::bad_alloc) |
| 23 | { |
| 24 | void *p; |
| 25 | |
| 26 | /* malloc (0) is unpredictable; avoid it. */ |
| 27 | if (sz == 0) |
| 28 | sz = 1; |
| 29 | p = (void *) malloc (sz); |
| 30 | while (p == 0) |
| 31 | { |
| 32 | ::abort(); |
| 33 | } |
| 34 | |
| 35 | return p; |
| 36 | } |
| 37 | |
| 38 | void* |
| 39 | operator new[] (std::size_t sz) throw (std::bad_alloc) |
| 40 | { |
| 41 | return ::operator new(sz); |
| 42 | } |
| 43 | |
| 44 | void * |
| 45 | operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw() |
| 46 | { |
| 47 | return ::operator new(sz, nothrow); |
| 48 | } |