Commit 32418bf1 authored by Jeremy Wright's avatar Jeremy Wright Committed by Facebook Github Bot 3

Upgrade ScopeGuard for Visual Studio 2015

Summary:Upgrade UncaughtExceptionCounter to use std::uncaught_exceptions on Visual Studio 2015 Update 1
Closes https://github.com/facebook/folly/pull/358

Reviewed By: yfeldblum

Differential Revision: D3066005

Pulled By: Orvid

fb-gh-sync-id: 6bc7129aa794257b1f6e7a084139d8a3a52fa4a8
shipit-source-id: 6bc7129aa794257b1f6e7a084139d8a3a52fa4a8
parent 6346da0d
......@@ -173,7 +173,8 @@ typedef ScopeGuardImplBase&& ScopeGuard;
namespace detail {
#if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS) || \
defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD)
defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD) || \
defined(FOLLY_EXCEPTION_COUNT_USE_STD)
/**
* ScopeGuard used for executing a function when leaving the current scope
......@@ -265,7 +266,8 @@ operator+(detail::ScopeGuardOnExit, FunctionType&& fn) {
= ::folly::detail::ScopeGuardOnExit() + [&]() noexcept
#if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS) || \
defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD)
defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD) || \
defined(FOLLY_EXCEPTION_COUNT_USE_STD)
#define SCOPE_FAIL \
auto FB_ANONYMOUS_VARIABLE(SCOPE_FAIL_STATE) \
= ::folly::detail::ScopeGuardOnFail() + [&]() noexcept
......
......@@ -27,11 +27,14 @@ struct __cxa_eh_globals;
// declared in cxxabi.h from libstdc++-v3
extern "C" __cxa_eh_globals* __cxa_get_globals() noexcept;
}
#elif defined(_MSC_VER) && (_MSC_VER >= 1400) // MSVC++ 8.0 or greater
#elif defined(_MSC_VER) && (_MSC_VER >= 1400) && \
(_MSC_VER < 1900) // MSVC++ 8.0 or greater
#define FOLLY_EXCEPTION_COUNT_USE_GETPTD
// forward declaration (originally defined in mtdll.h from MSVCRT)
struct _tiddata;
extern "C" _tiddata* _getptd(); // declared in mtdll.h from MSVCRT
#elif defined(_MSC_VER) && (_MSC_VER >= 1900) // MSVC++ 2015
#define FOLLY_EXCEPTION_COUNT_USE_STD
#else
// Raise an error when trying to use this on unsupported platforms.
#error "Unsupported platform, don't include this header."
......@@ -84,6 +87,8 @@ inline int UncaughtExceptionCounter::getUncaughtExceptionCount() noexcept {
// The offset below returns _tiddata::_ProcessingThrow.
return *(reinterpret_cast<int*>(static_cast<char*>(
static_cast<void*>(_getptd())) + sizeof(void*) * 28 + 0x4 * 8));
#elif defined(FOLLY_EXCEPTION_COUNT_USE_STD)
return std::uncaught_exceptions();
#endif
}
......
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