Commit f8ccf160 authored by Kenton Varda's avatar Kenton Varda

Improve uncaughtExceptionCount().

Including cxxabi.h caused build failures because our definition of __cxa_get_globals conflicted with the one in the header (despite being in a different namespace -- apparently becaues of `extern "C"` the compiler considers them to be conflicting). Annoyingly, __cxa_get_globals is only defined by GNU's cxxabi.h and not LLVM's. But LLVM has a nicer __cxa_uncaught_exceptions() that we can perhaps use.

Also in C++17 there is a standard function we can call instead.
parent 4adc8128
......@@ -841,7 +841,13 @@ void throwRecoverableException(kj::Exception&& exception, uint ignoreCount) {
namespace _ { // private
#if __GNUC__
#if __cplusplus >= 201703L
uint uncaughtExceptionCount() {
return std::uncaught_exceptions();
}
#elif __GNUC__
// Horrible -- but working -- hack: We can dig into __cxa_get_globals() in order to extract the
// count of uncaught exceptions. This function is part of the C++ ABI implementation used on Linux,
......@@ -865,17 +871,16 @@ struct FakeEhGlobals {
uint uncaughtExceptions;
};
// Because of the 'extern "C"', the symbol name is not mangled and thus the namespace is effectively
// ignored for linking. Thus it doesn't matter that we are declaring __cxa_get_globals() in a
// different namespace from the ABI's definition.
extern "C" {
FakeEhGlobals* __cxa_get_globals();
}
// LLVM's libstdc++ doesn't declare __cxa_get_globals in its cxxabi.h. GNU does. Because it is
// extern "C", the compiler wills get upset if we re-declare it even in a different namespace.
#if _LIBCPPABI_VERSION
extern "C" void* __cxa_get_globals();
#else
using abi::__cxa_get_globals;
#endif
uint uncaughtExceptionCount() {
// TODO(perf): Use __cxa_get_globals_fast()? Requires that __cxa_get_globals() has been called
// from somewhere.
return __cxa_get_globals()->uncaughtExceptions;
return reinterpret_cast<FakeEhGlobals*>(__cxa_get_globals())->uncaughtExceptions;
}
#elif _MSC_VER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment