summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2009-04-25 01:01:23 +0000
committercsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2009-04-25 01:01:23 +0000
commitad03b009ef2046cee9dc38afe022b487de37db5c (patch)
tree38a6cac76ed15716b01e88d8e123fe0c5784c626
parent1894763f57b00f72a720c4c126815c073d9ed0f3 (diff)
downloadgperftools-ad03b009ef2046cee9dc38afe022b487de37db5c.tar.gz
In the case of windows with HAS_EXCEPTIONS turned off we weren't able
to use the std::set_new_handler correctly. Rework the #ifdefs to allow use of the std_new_handler, but ignore the exceptions. Patch submitted by mbelshe. git-svn-id: http://gperftools.googlecode.com/svn/trunk@72 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
-rw-r--r--src/tcmalloc.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/tcmalloc.cc b/src/tcmalloc.cc
index 9dac1fa..4417f5b 100644
--- a/src/tcmalloc.cc
+++ b/src/tcmalloc.cc
@@ -896,7 +896,7 @@ static SpinLock set_new_handler_lock(SpinLock::LINKER_INITIALIZED);
inline void* cpp_alloc(size_t size, bool nothrow) {
for (;;) {
void* p = do_malloc(size);
-#if defined(PREANSINEW) || (defined(__GNUC__) && !defined(__EXCEPTIONS)) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)
+#ifdef PREANSINEW
return p;
#else
if (p == NULL) { // allocation failed
@@ -910,6 +910,15 @@ inline void* cpp_alloc(size_t size, bool nothrow) {
nh = std::set_new_handler(0);
(void) std::set_new_handler(nh);
}
+#if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)
+ if (nh) {
+ // Since exceptions are disabled, we don't really know if new_handler
+ // failed. Assume it will abort if it fails.
+ (*nh)();
+ continue;
+ }
+ return 0;
+#else
// If no new_handler is established, the allocation failed.
if (!nh) {
if (nothrow) return 0;
@@ -924,10 +933,11 @@ inline void* cpp_alloc(size_t size, bool nothrow) {
if (!nothrow) throw;
return p;
}
+#endif // (defined(__GNUC__) && !defined(__EXCEPTIONS)) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)
} else { // allocation success
return p;
}
-#endif
+#endif // PREANSINEW
}
}