diff options
author | theraven <theraven@FreeBSD.org> | 2013-01-11 15:05:55 +0000 |
---|---|---|
committer | theraven <theraven@FreeBSD.org> | 2013-01-11 15:05:55 +0000 |
commit | f8a3c6151f84669a265d291556c626e90b92b208 (patch) | |
tree | 714345d8e051db9af44b11c7c3f9f9ee2bef18d1 /contrib/libcxxrt/memory.cc | |
parent | 607c3680d90935ee21ad3e58fdd171d15ebb3284 (diff) | |
parent | e8f1f5bd311be550e3041d55f84c95d7b5990797 (diff) | |
download | FreeBSD-src-f8a3c6151f84669a265d291556c626e90b92b208.zip FreeBSD-src-f8a3c6151f84669a265d291556c626e90b92b208.tar.gz |
Merge new version of libcxxrt. This brings in three fixes:
- Don't treat pointers to members as pointers in catch blocks (they're usually
fat pointers).
- Correctly catch foreign exceptions in catchalls.
- Ensure that a happens-before relationship is established when setting
terminate handlers in one thread and calling them in another.
Diffstat (limited to 'contrib/libcxxrt/memory.cc')
-rw-r--r-- | contrib/libcxxrt/memory.cc | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/contrib/libcxxrt/memory.cc b/contrib/libcxxrt/memory.cc index bd7fd22..cc879e0 100644 --- a/contrib/libcxxrt/memory.cc +++ b/contrib/libcxxrt/memory.cc @@ -36,14 +36,8 @@ #include <stddef.h> #include <stdlib.h> #include "stdexcept.h" +#include "atomic.h" -#ifndef __has_builtin -#define __has_builtin(x) 0 -#endif - -#if !__has_builtin(__sync_swap) -#define __sync_swap __sync_lock_test_and_set -#endif namespace std { @@ -67,7 +61,12 @@ namespace std __attribute__((weak)) new_handler set_new_handler(new_handler handler) { - return __sync_swap(&new_handl, handler); + return ATOMIC_SWAP(&new_handl, handler); + } + __attribute__((weak)) + new_handler get_new_handler(void) + { + return ATOMIC_LOAD(&new_handl); } } @@ -75,12 +74,17 @@ namespace std __attribute__((weak)) void* operator new(size_t size) { + if (0 == size) + { + size = 1; + } void * mem = malloc(size); while (0 == mem) { - if (0 != new_handl) + new_handler h = std::get_new_handler(); + if (0 != h) { - new_handl(); + h(); } else { @@ -95,14 +99,19 @@ 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) { - if (0 != new_handl) + new_handler h = std::get_new_handler(); + if (0 != h) { try { - new_handl(); + h(); } catch (...) { |