Move the libstdc++ code path to a separate file.

We need to #include <exception> for this to work, but this brings in the
public definition of `std::type_info` and, unfortunately, that breaks
the private definition that we need in this compilation unit.
main
David Chisnall 6 years ago committed by David Chisnall
parent 55a4719976
commit 55819ce107

@ -82,7 +82,7 @@ if (WIN32)
list(APPEND libobjc_CXX_SRCS eh_win32_msvc.cc) list(APPEND libobjc_CXX_SRCS eh_win32_msvc.cc)
else () else ()
list(APPEND libobjc_C_SRCS eh_personality.c) list(APPEND libobjc_C_SRCS eh_personality.c)
set(libobjcxx_CXX_SRCS objcxx_eh.cc) set(libobjcxx_CXX_SRCS objcxx_eh.cc libstdcxx_current_primary_exception.cc)
endif (WIN32) endif (WIN32)

@ -0,0 +1,19 @@
#include "visibility.h"
#include <exception>
#ifdef __GLIBCXX__
/**
* libsupc++ doesn't expose __cxa_current_primary_exception, so implement this
* using the libstdc++ wrapper. The exception pointer in the
* `std::exception_ptr` object is reference counted, so stealing it by poking
* at the pointer directly means that we acquire it with a reference count of
* 1.
*/
PRIVATE extern "C" void *__cxa_current_primary_exception()
{
std::exception_ptr p = std::current_exception();
void *obj = *(void**)&p;
*(void**)&p = nullptr;
return obj;
}
#endif

@ -22,19 +22,8 @@ extern "C"
void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void __cxa_throw(void *thrown_exception, std::type_info *tinfo,
void (*dest)(void *)); void (*dest)(void *));
#ifdef __GLIBCXX__
#include <exception>
static void *__cxa_current_primary_exception()
{
std::exception_ptr p = std::current_exception();
void *obj = *(void**)&p;
*(void**)&p = nullptr;
return obj;
}
#else
extern "C" extern "C"
void *__cxa_current_primary_exception(); void *__cxa_current_primary_exception();
#endif
using namespace __cxxabiv1; using namespace __cxxabiv1;

Loading…
Cancel
Save