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