Commit 25189ad9 authored by Andrew Gallagher's avatar Andrew Gallagher Committed by Tudor Bosman

folly/Malloc.h: use libstdc++-safe exception wrappers

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
parent 5eeb7509
...@@ -62,6 +62,8 @@ namespace folly { ...@@ -62,6 +62,8 @@ namespace folly {
#include <new> #include <new>
#include <bits/functexcept.h>
/** /**
* Declare rallocm() and malloc_usable_size() as weak symbols. It * Declare rallocm() and malloc_usable_size() as weak symbols. It
* will be provided by jemalloc if we are using jemalloc, or it will * will be provided by jemalloc if we are using jemalloc, or it will
...@@ -144,19 +146,19 @@ static const size_t jemallocMinInPlaceExpandable = 4096; ...@@ -144,19 +146,19 @@ static const size_t jemallocMinInPlaceExpandable = 4096;
*/ */
inline void* checkedMalloc(size_t size) { inline void* checkedMalloc(size_t size) {
void* p = malloc(size); void* p = malloc(size);
if (!p) throw std::bad_alloc(); if (!p) std::__throw_bad_alloc();
return p; return p;
} }
inline void* checkedCalloc(size_t n, size_t size) { inline void* checkedCalloc(size_t n, size_t size) {
void* p = calloc(n, size); void* p = calloc(n, size);
if (!p) throw std::bad_alloc(); if (!p) std::__throw_bad_alloc();
return p; return p;
} }
inline void* checkedRealloc(void* ptr, size_t size) { inline void* checkedRealloc(void* ptr, size_t size) {
void* p = realloc(ptr, size); void* p = realloc(ptr, size);
if (!p) throw std::bad_alloc(); if (!p) std::__throw_bad_alloc();
return p; return p;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment