mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-06-14 16:05:48 +03:00
Replace experimental_infallible_new with compile-time flag
The runtime option aborted on every OOM, breaking new(std::nothrow) semantics. Replace with configure-time --enable-cxx-infallible-new (default off): when on, throwing new aborts (size logged) and nothrow returns null; when off, standard new_handler + bad_alloc / null behavior is preserved. Under LTO the on-path lets the compiler prove operator new is no-throw.
This commit is contained in:
parent
a6048680a8
commit
160ab9d7f6
19 changed files with 103 additions and 44 deletions
|
|
@ -66,20 +66,20 @@ void operator delete[](
|
|||
JEMALLOC_NOINLINE
|
||||
static void *
|
||||
handleOOM(std::size_t size, bool nothrow) {
|
||||
if (opt_experimental_infallible_new) {
|
||||
const char *huge_warning = (size >= ((std::size_t)1 << 30))
|
||||
? "This may be caused by heap corruption, if the large size "
|
||||
"is unexpected (suggest building with sanitizers for "
|
||||
"debugging)."
|
||||
: "";
|
||||
|
||||
safety_check_fail(
|
||||
"<jemalloc>: Allocation of size %zu failed. "
|
||||
"%s opt.experimental_infallible_new is true. Aborting.\n",
|
||||
size, huge_warning);
|
||||
#ifdef JEMALLOC_INFALLIBLE_NEW
|
||||
if (nothrow) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char *huge_warning = (size >= ((std::size_t)1 << 30))
|
||||
? "This may be caused by heap corruption, if the large size "
|
||||
"is unexpected (suggest building with sanitizers for "
|
||||
"debugging). "
|
||||
: "";
|
||||
safety_check_fail(
|
||||
"<jemalloc>: Allocation of size %zu failed. %sAborting.\n",
|
||||
size, huge_warning);
|
||||
return nullptr;
|
||||
#else
|
||||
void *ptr = nullptr;
|
||||
|
||||
while (ptr == nullptr) {
|
||||
|
|
@ -108,6 +108,7 @@ handleOOM(std::size_t size, bool nothrow) {
|
|||
#endif
|
||||
}
|
||||
return ptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <bool IsNoExcept>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue