diff options
author | theraven <theraven@FreeBSD.org> | 2013-07-10 16:28:24 +0000 |
---|---|---|
committer | theraven <theraven@FreeBSD.org> | 2013-07-10 16:28:24 +0000 |
commit | 214e4f8fe625ad54aac3b215909e0b994a5768ec (patch) | |
tree | f757844d307e5ebbf92ab857f2376cceb7807147 /contrib/libcxxrt/memory.cc | |
parent | c660176671bf640bee3fd09dbfa32ad187a9b942 (diff) | |
download | FreeBSD-src-214e4f8fe625ad54aac3b215909e0b994a5768ec.zip FreeBSD-src-214e4f8fe625ad54aac3b215909e0b994a5768ec.tar.gz |
Import new libcxxrt / libc++. This brings some bug fixes, including a potential race condition for static initialisers.
Diffstat (limited to 'contrib/libcxxrt/memory.cc')
-rw-r--r-- | contrib/libcxxrt/memory.cc | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/contrib/libcxxrt/memory.cc b/contrib/libcxxrt/memory.cc index cc879e0..c8d28fc 100644 --- a/contrib/libcxxrt/memory.cc +++ b/contrib/libcxxrt/memory.cc @@ -99,40 +99,21 @@ void* operator new(size_t size) __attribute__((weak)) void* operator new(size_t size, const std::nothrow_t &) throw() { - if (0 == size) - { - size = 1; - } - void *mem = malloc(size); - while (0 == mem) - { - new_handler h = std::get_new_handler(); - if (0 != h) - { - try - { - h(); - } - catch (...) - { - // nothrow operator new should return NULL in case of - // std::bad_alloc exception in new handler - return NULL; - } - } - else - { - return NULL; - } - mem = malloc(size); + try { + return :: operator new(size); + } catch (...) { + // nothrow operator new should return NULL in case of + // std::bad_alloc exception in new handler + return NULL; } - - return mem; } __attribute__((weak)) void operator delete(void * ptr) +#if __cplusplus < 201000L +throw() +#endif { free(ptr); } @@ -140,13 +121,32 @@ void operator delete(void * ptr) __attribute__((weak)) void * operator new[](size_t size) +#if __cplusplus < 201000L +throw(std::bad_alloc) +#endif { return ::operator new(size); } __attribute__((weak)) -void operator delete[](void * ptr) throw() +void * operator new[](size_t size, const std::nothrow_t &) throw() +{ + try { + return ::operator new[](size); + } catch (...) { + // nothrow operator new should return NULL in case of + // std::bad_alloc exception in new handler + return NULL; + } +} + + +__attribute__((weak)) +void operator delete[](void * ptr) +#if __cplusplus < 201000L +throw() +#endif { ::operator delete(ptr); } |