mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Simplify logic selecting between signal handling/SEH/nothing
It was a bit of a mess previously
This commit is contained in:
parent
0c5df42c28
commit
7b6e49d795
@ -59,6 +59,12 @@
|
|||||||
#endif // __clang__
|
#endif // __clang__
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Assume that non-Windows platforms support posix signals by default
|
||||||
|
#if !defined(CATCH_PLATFORM_WINDOWS)
|
||||||
|
#define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// We know some environments not to support full POSIX signals
|
// We know some environments not to support full POSIX signals
|
||||||
#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__)
|
#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__)
|
||||||
@ -121,7 +127,7 @@
|
|||||||
# define CATCH_CONFIG_WINDOWS_SEH
|
# define CATCH_CONFIG_WINDOWS_SEH
|
||||||
#endif
|
#endif
|
||||||
// This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
|
// This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
|
||||||
#if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
|
#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
|
||||||
# define CATCH_CONFIG_POSIX_SIGNALS
|
# define CATCH_CONFIG_POSIX_SIGNALS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -17,24 +17,14 @@
|
|||||||
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(CATCH_PLATFORM_WINDOWS) && defined(CATCH_CONFIG_WINDOWS_SEH)) || defined(CATCH_CONFIG_POSIX_SIGNALS)
|
|
||||||
namespace {
|
namespace {
|
||||||
// Report the error condition
|
// Report the error condition
|
||||||
void reportFatal( char const * const message ) {
|
void reportFatal( char const * const message ) {
|
||||||
Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message );
|
Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
|
#if defined( CATCH_CONFIG_WINDOWS_SEH )
|
||||||
|
|
||||||
# if !defined ( CATCH_CONFIG_WINDOWS_SEH )
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
void FatalConditionHandler::reset() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
# else // CATCH_CONFIG_WINDOWS_SEH is defined
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
struct SignalDefs { DWORD id; const char* name; };
|
struct SignalDefs { DWORD id; const char* name; };
|
||||||
@ -74,7 +64,6 @@ namespace Catch {
|
|||||||
|
|
||||||
void FatalConditionHandler::reset() {
|
void FatalConditionHandler::reset() {
|
||||||
if (isSet) {
|
if (isSet) {
|
||||||
// Unregister handler and restore the old guarantee
|
|
||||||
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
|
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
|
||||||
SetThreadStackGuarantee(&guaranteeSize);
|
SetThreadStackGuarantee(&guaranteeSize);
|
||||||
exceptionHandlerHandle = nullptr;
|
exceptionHandlerHandle = nullptr;
|
||||||
@ -93,20 +82,7 @@ PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr;
|
|||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
# endif // CATCH_CONFIG_WINDOWS_SEH
|
#elif defined( CATCH_CONFIG_POSIX_SIGNALS )
|
||||||
|
|
||||||
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
|
||||||
|
|
||||||
# if !defined(CATCH_CONFIG_POSIX_SIGNALS)
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
void FatalConditionHandler::reset() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# else // CATCH_CONFIG_POSIX_SIGNALS is defined
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -178,9 +154,13 @@ namespace Catch {
|
|||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
# endif // CATCH_CONFIG_POSIX_SIGNALS
|
#else
|
||||||
|
|
||||||
#endif // not Windows
|
namespace Catch {
|
||||||
|
void FatalConditionHandler::reset() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // signals/SEH handling
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
# pragma GCC diagnostic pop
|
# pragma GCC diagnostic pop
|
||||||
|
@ -14,18 +14,7 @@
|
|||||||
#include "catch_windows_h_proxy.h"
|
#include "catch_windows_h_proxy.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
|
#if defined( CATCH_CONFIG_WINDOWS_SEH )
|
||||||
|
|
||||||
|
|
||||||
# if !defined ( CATCH_CONFIG_WINDOWS_SEH )
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
struct FatalConditionHandler {
|
|
||||||
void reset();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
# else // CATCH_CONFIG_WINDOWS_SEH is defined
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -44,20 +33,7 @@ namespace Catch {
|
|||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
# endif // CATCH_CONFIG_WINDOWS_SEH
|
#elif defined ( CATCH_CONFIG_POSIX_SIGNALS )
|
||||||
|
|
||||||
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
|
||||||
|
|
||||||
# if !defined(CATCH_CONFIG_POSIX_SIGNALS)
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
struct FatalConditionHandler {
|
|
||||||
void reset();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# else // CATCH_CONFIG_POSIX_SIGNALS is defined
|
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
@ -66,7 +42,7 @@ namespace Catch {
|
|||||||
struct FatalConditionHandler {
|
struct FatalConditionHandler {
|
||||||
|
|
||||||
static bool isSet;
|
static bool isSet;
|
||||||
static struct sigaction oldSigActions[];// [sizeof(signalDefs) / sizeof(SignalDefs)];
|
static struct sigaction oldSigActions[];
|
||||||
static stack_t oldSigStack;
|
static stack_t oldSigStack;
|
||||||
static char altStackMem[];
|
static char altStackMem[];
|
||||||
|
|
||||||
@ -79,8 +55,15 @@ namespace Catch {
|
|||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
# endif // CATCH_CONFIG_POSIX_SIGNALS
|
|
||||||
|
|
||||||
#endif // not Windows
|
#else
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
struct FatalConditionHandler {
|
||||||
|
void reset();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user