folly/Malloc.h: use libstdc++-safe exception wrappers
authorAndrew Gallagher <agallagher@fb.com>
Wed, 11 Jul 2012 21:03:19 +0000 (14:03 -0700)
committerTudor Bosman <tudorb@fb.com>
Fri, 13 Jul 2012 23:29:17 +0000 (16:29 -0700)
Summary:
gcc errors out when code that throws is compiled with
'-fno-exceptions'.  Since we add Malloc.h into our custom libstdc++
use the exception wrappers from functexcept.h so that they can build
with third-party projects that use '-fno-exceptions'.

Test Plan:
Built llvm in the gcc-4.7.1-glibc-2.14.1-fb platform with these
changes.

Reviewed By: tudorb@fb.com

FB internal diff: D516577

folly/Malloc.h

index 7aadfc8fc9558d38cf56eff76d9dd1e44f4a52cc..e43c2afef0ba4cfd537a92407adecb440ced994d 100644 (file)
@@ -62,6 +62,8 @@ namespace folly {
 
 #include <new>
 
+#include <bits/functexcept.h>
+
 /**
  * Declare rallocm() and malloc_usable_size() as weak symbols.  It
  * will be provided by jemalloc if we are using jemalloc, or it will
@@ -144,19 +146,19 @@ static const size_t jemallocMinInPlaceExpandable = 4096;
  */
 inline void* checkedMalloc(size_t size) {
   void* p = malloc(size);
-  if (!p) throw std::bad_alloc();
+  if (!p) std::__throw_bad_alloc();
   return p;
 }
 
 inline void* checkedCalloc(size_t n, size_t size) {
   void* p = calloc(n, size);
-  if (!p) throw std::bad_alloc();
+  if (!p) std::__throw_bad_alloc();
   return p;
 }
 
 inline void* checkedRealloc(void* ptr, size_t size) {
   void* p = realloc(ptr, size);
-  if (!p) throw std::bad_alloc();
+  if (!p) std::__throw_bad_alloc();
   return p;
 }