[libcxx-commits] [libcxx] [libc++] [libc++abi] Initialize exception directly in make_exception_ptr if __cxa_init_primary_exception is available in ABI-library (PR #65534)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 25 00:03:16 PDT 2023


================
@@ -34,6 +48,44 @@ exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept
     return *this;
 }
 
+#  ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+void *exception_ptr::__init_native_exception(size_t size, type_info *tinfo, void (*dest)(void *)) noexcept
+{
+    #if !defined(_WIN32)
+    // We perform a runtime lookup of __cxa_init_primary_exception to
+    // preserve compability with older versions of libcxxrt/libcxxabi.
+    // If the function is not present we return nullptr because no meaningful work can be done,
+    // and the caller knows how to handle this (it fallbacks to throw + catch).
+    using CxaInitPrimaryExceptionPrototype = void *(*)(void *, type_info *, void(*)(void *));
+    static CxaInitPrimaryExceptionPrototype cxa_init_primary_exception_fn = reinterpret_cast<CxaInitPrimaryExceptionPrototype>(
+        dlsym(RTLD_DEFAULT, "__cxa_init_primary_exception"));
----------------
itrofimow wrote:

Apparently that doesn't seem to work with Apple.
I'm fine with that, since i'm only interested in linux platform, and for now i ifdefed-out Apple

https://github.com/llvm/llvm-project/pull/65534


More information about the libcxx-commits mailing list