[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
Fri Oct 27 01:33:58 PDT 2023


================
@@ -53,6 +67,36 @@ exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept
     return *this;
 }
 
+#  if defined(_LIBCPP_EXCEPTION_PTR_DIRECT_INIT)
+void *exception_ptr::__init_native_exception(size_t size, type_info* tinfo, void (*dest)(void*)) noexcept
+{
+    void *(*cxa_init_primary_exception_fn)(void*, std::type_info*, void(*)(void*)) = __cxa_init_primary_exception;
+    if (cxa_init_primary_exception_fn != nullptr)
+    {
+        void* __ex = __cxa_allocate_exception(size);
+        (void)cxa_init_primary_exception_fn(__ex, tinfo, dest);
+        return __ex;
+    }
+    else
+    {
+        return nullptr;
+    }
+}
+
+void exception_ptr::__free_native_exception(void* thrown_object) noexcept
+{
+    __cxa_free_exception(thrown_object);
+}
+
+exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept
+{
+    exception_ptr ptr{};
+    new (reinterpret_cast<void*>(&ptr)) __exception_ptr::exception_ptr(__e);
----------------
itrofimow wrote:

Do they? 
https://github.com/llvm/llvm-project/blob/ea1909f82ceca30b009701f1d349247f8fbf1c3e/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp#L42-L47

My understanding is that this is a hackery of course, but the hackery that should work:
https://github.com/llvm/llvm-project/blob/ea1909f82ceca30b009701f1d349247f8fbf1c3e/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp#L13-L16

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


More information about the libcxx-commits mailing list