From 517839fb3f7f0fd7823dadce69ab791628d1bc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 25 Apr 2020 14:07:50 +0200 Subject: [PATCH] Small cleanup of fatal condition handler --- src/CMakeLists.txt | 4 ++-- ....cpp => catch_fatal_condition_handler.cpp} | 19 ++----------------- ....hpp => catch_fatal_condition_handler.hpp} | 8 +++----- src/catch2/internal/catch_run_context.cpp | 8 +++++--- 4 files changed, 12 insertions(+), 27 deletions(-) rename src/catch2/internal/{catch_fatal_condition.cpp => catch_fatal_condition_handler.cpp} (95%) rename src/catch2/internal/{catch_fatal_condition.hpp => catch_fatal_condition_handler.hpp} (91%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3028e322..44e7d3ea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,7 +55,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/internal/catch_enum_values_registry.hpp ${SOURCES_DIR}/internal/catch_errno_guard.hpp ${SOURCES_DIR}/internal/catch_exception_translator_registry.hpp - ${SOURCES_DIR}/internal/catch_fatal_condition.hpp + ${SOURCES_DIR}/internal/catch_fatal_condition_handler.hpp ${SOURCES_DIR}/generators/catch_generator_exception.hpp ${SOURCES_DIR}/generators/catch_generators.hpp ${SOURCES_DIR}/generators/catch_generators_adapters.hpp @@ -141,7 +141,7 @@ set(IMPL_SOURCES ${SOURCES_DIR}/internal/catch_enum_values_registry.cpp ${SOURCES_DIR}/internal/catch_errno_guard.cpp ${SOURCES_DIR}/internal/catch_exception_translator_registry.cpp - ${SOURCES_DIR}/internal/catch_fatal_condition.cpp + ${SOURCES_DIR}/internal/catch_fatal_condition_handler.cpp ${SOURCES_DIR}/generators/catch_generator_exception.cpp ${SOURCES_DIR}/generators/catch_generators.cpp ${SOURCES_DIR}/interfaces/catch_interfaces_capture.cpp diff --git a/src/catch2/internal/catch_fatal_condition.cpp b/src/catch2/internal/catch_fatal_condition_handler.cpp similarity index 95% rename from src/catch2/internal/catch_fatal_condition.cpp rename to src/catch2/internal/catch_fatal_condition_handler.cpp index 1a858569..d6cc306a 100644 --- a/src/catch2/internal/catch_fatal_condition.cpp +++ b/src/catch2/internal/catch_fatal_condition_handler.cpp @@ -7,7 +7,7 @@ * */ -#include +#include #include #include @@ -75,10 +75,6 @@ namespace Catch { } } - FatalConditionHandler::~FatalConditionHandler() { - reset(); - } - bool FatalConditionHandler::isSet = false; ULONG FatalConditionHandler::guaranteeSize = 0; PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr; @@ -94,7 +90,7 @@ namespace Catch { int id; const char* name; }; - + // 32kb for the alternate stack seems to be sufficient. However, this value // is experimentally determined, so that's not guaranteed. static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ; @@ -138,11 +134,6 @@ namespace Catch { } } - - FatalConditionHandler::~FatalConditionHandler() { - reset(); - } - void FatalConditionHandler::reset() { if( isSet ) { // Set signals back to previous values -- hopefully nobody overwrote them in the meantime @@ -163,12 +154,6 @@ namespace Catch { } // namespace Catch -#else - -namespace Catch { - void FatalConditionHandler::reset() {} -} - #endif // signals/SEH handling #if defined(__GNUC__) diff --git a/src/catch2/internal/catch_fatal_condition.hpp b/src/catch2/internal/catch_fatal_condition_handler.hpp similarity index 91% rename from src/catch2/internal/catch_fatal_condition.hpp rename to src/catch2/internal/catch_fatal_condition_handler.hpp index f7c2064e..f9c94d85 100644 --- a/src/catch2/internal/catch_fatal_condition.hpp +++ b/src/catch2/internal/catch_fatal_condition_handler.hpp @@ -23,7 +23,7 @@ namespace Catch { static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo); FatalConditionHandler(); static void reset(); - ~FatalConditionHandler(); + ~FatalConditionHandler() { reset(); } private: static bool isSet; @@ -49,7 +49,7 @@ namespace Catch { static void handleSignal( int sig ); FatalConditionHandler(); - ~FatalConditionHandler(); + ~FatalConditionHandler() { reset(); } static void reset(); }; @@ -59,9 +59,7 @@ namespace Catch { #else namespace Catch { - struct FatalConditionHandler { - void reset(); - }; + struct FatalConditionHandler {}; } #endif diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index d4b6bdac..5ea1c515 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include @@ -377,9 +377,11 @@ namespace Catch { } void RunContext::invokeActiveTestCase() { - FatalConditionHandler fatalConditionHandler; // Handle signals + // We need to register a handler for signals/structured exceptions + // before running the tests themselves, or the binary can crash + // without failed test being reported. + FatalConditionHandler _; m_activeTestCase->invoke(); - fatalConditionHandler.reset(); } void RunContext::handleUnfinishedSections() {