mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 21:23:06 +00:00
Replace std::__throw_bad_alloc call with standard C++ (#2900)
* Replace std::__throw_bad_alloc call with standard C++ Since December of 2025, std::__throw_bad_alloc is no longer visible through #include <new> causing jemalloc build failures with gcc 16. As far as I can tell, all std::__throw_bad_alloc did was arrange to raise a std::bad_alloc exception if exceptions are enabled. I am not sure whether its usage was truly meaningful in jemalloc since the call is wrapped in a try catch and any usage of try catch is considered an error when compiling with -fno-exceptions on gcc, at least. This change adds a check to configure.ac that determines whether exceptions are enabled by compiling a simple try catch that raises a std::bad_alloc exception. If that test succeeds, the macro JEMALLOC_HAVE_CXX_EXCEPTIONS is defined, and jemalloc will raise an exception. Otherwise, we call std::terminate() to abort. This was tested on FreeBSD with the gcc16 port with and without exceptions enabled. * Replace std::set_new_handler calls with std::get_new_handler Previously, std::set_new_handler was used as a workaround for compilers with only partial support for C++11. Now that C++14 is a requirement to enable C++ support, we can assume std::get_new_handler is available.
This commit is contained in:
23
configure.ac
23
configure.ac
@@ -374,7 +374,30 @@ fi
|
||||
if test "x$enable_cxx" = "x1"; then
|
||||
AC_DEFINE([JEMALLOC_ENABLE_CXX], [ ], [ ])
|
||||
fi
|
||||
if test "x$enable_cxx" = "x1"; then
|
||||
dnl Now check whether the C++ compiler has exceptions enabled.
|
||||
AC_LANG_PUSH([C++])
|
||||
SAVED_CXXFLAGS="${CXXFLAGS}"
|
||||
CXXFLAGS="${CXXFLAGS} ${EXTRA_CXXFLAGS}"
|
||||
JE_COMPILABLE([C++ exception support], [
|
||||
#include <new>
|
||||
], [
|
||||
try {
|
||||
throw std::bad_alloc();
|
||||
} catch (const std::bad_alloc &) {
|
||||
}
|
||||
], [je_cv_cxx_exceptions])
|
||||
CXXFLAGS="${SAVED_CXXFLAGS}"
|
||||
AC_LANG_POP([C++])
|
||||
if test "x${je_cv_cxx_exceptions}" = "xyes" ; then
|
||||
AC_DEFINE([JEMALLOC_HAVE_CXX_EXCEPTIONS], [ ], [ ])
|
||||
enable_cxx_exceptions="1"
|
||||
else
|
||||
enable_cxx_exceptions="0"
|
||||
fi
|
||||
fi
|
||||
AC_SUBST([enable_cxx])
|
||||
AC_SUBST([enable_cxx_exceptions])
|
||||
AC_SUBST([CONFIGURE_CXXFLAGS])
|
||||
AC_SUBST([SPECIFIED_CXXFLAGS])
|
||||
AC_SUBST([EXTRA_CXXFLAGS])
|
||||
|
||||
Reference in New Issue
Block a user