From 32418bf1d0d11c0158670d11fe04a8a5eec57269 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Fri, 18 Mar 2016 17:11:23 -0700 Subject: [PATCH] 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 --- folly/ScopeGuard.h | 6 ++++-- folly/detail/UncaughtExceptionCounter.h | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/folly/ScopeGuard.h b/folly/ScopeGuard.h index 3822e4d1..8b16fae1 100644 --- a/folly/ScopeGuard.h +++ b/folly/ScopeGuard.h @@ -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 diff --git a/folly/detail/UncaughtExceptionCounter.h b/folly/detail/UncaughtExceptionCounter.h index 7399e18e..b0119c06 100644 --- a/folly/detail/UncaughtExceptionCounter.h +++ b/folly/detail/UncaughtExceptionCounter.h @@ -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(static_cast( static_cast(_getptd())) + sizeof(void*) * 28 + 0x4 * 8)); +#elif defined(FOLLY_EXCEPTION_COUNT_USE_STD) + return std::uncaught_exceptions(); #endif } -- 2.34.1