Skip to content

Commit

Permalink
fixup! Fix compilation with libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamStepan committed Jun 25, 2019
1 parent 8d7bce6 commit 34aa34e
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions include/superior_mysqlpp/uncaught_exception_counter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,19 @@

#pragma once

#include <cxxabi.h>
#include <exception>

namespace SuperiorMySqlpp
{
inline int uncaughtExceptions() noexcept
{
#if defined(__clang__) && _LIBCPPABI_VERSION >= 1002
return static_cast<int>(__cxxabiv1::__cxa_uncaught_exceptions());
#else
auto* globalsPtr = __cxxabiv1::__cxa_get_globals();
auto* globalsEreasedPtr = reinterpret_cast<char*>(globalsPtr);
auto* uncaughtExceptionsErasedPtr = globalsEreasedPtr + sizeof(void*);
auto* uncaughtExceptionsPtr = reinterpret_cast<int*>(uncaughtExceptionsErasedPtr);
return *uncaughtExceptionsPtr;
#endif
}

class UncaughtExceptionCounter
{
private:
int exceptionCount;
std::exception_ptr oldException{std::current_exception()};

public:
UncaughtExceptionCounter() noexcept
: exceptionCount{uncaughtExceptions()}
{}

bool isNewUncaughtException() const noexcept
{
return uncaughtExceptions() > exceptionCount;
return std::current_exception() != oldException;
}
};
}

0 comments on commit 34aa34e

Please sign in to comment.