mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 11:12:25 +01:00
Fixes for C++03 compatibility.
This commit is contained in:
parent
e810d9602e
commit
611d1af5a6
@ -37,8 +37,6 @@ namespace Catch {
|
|||||||
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <memory>
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -64,10 +62,10 @@ namespace Catch {
|
|||||||
|
|
||||||
FatalConditionHandler(): m_isSet(true), m_altStackMem(new char[SIGSTKSZ]) {
|
FatalConditionHandler(): m_isSet(true), m_altStackMem(new char[SIGSTKSZ]) {
|
||||||
stack_t sigStack;
|
stack_t sigStack;
|
||||||
sigStack.ss_sp = m_altStackMem.get();
|
sigStack.ss_sp = m_altStackMem;
|
||||||
sigStack.ss_size = SIGSTKSZ;
|
sigStack.ss_size = SIGSTKSZ;
|
||||||
sigStack.ss_flags = 0;
|
sigStack.ss_flags = 0;
|
||||||
sigaltstack(&sigStack, &m_oldSigActions);
|
sigaltstack(&sigStack, &m_oldSigStack);
|
||||||
struct sigaction sa = { 0 };
|
struct sigaction sa = { 0 };
|
||||||
|
|
||||||
sa.sa_handler = handleSignal;
|
sa.sa_handler = handleSignal;
|
||||||
@ -78,22 +76,24 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
~FatalConditionHandler() {
|
~FatalConditionHandler() {
|
||||||
reset();
|
reset();
|
||||||
|
delete[] m_altStackMem;
|
||||||
}
|
}
|
||||||
void reset() {
|
void reset() {
|
||||||
if( m_isSet ) {
|
if( m_isSet ) {
|
||||||
// Set signals back to previous values -- hopefully nobody overwrote them in the meantime
|
// Set signals back to previous values -- hopefully nobody overwrote them in the meantime
|
||||||
for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
|
for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
|
||||||
sigaction(signalDefs[i].id, &m_oldSigActions[i], nullptr);
|
sigaction(signalDefs[i].id, &m_oldSigActions[i], CATCH_NULL);
|
||||||
}
|
}
|
||||||
// Return the old stack
|
// Return the old stack
|
||||||
sigaltstack(&m_oldSigStack, nullptr);
|
sigaltstack(&m_oldSigStack, CATCH_NULL);
|
||||||
m_isSet = false;
|
m_isSet = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool m_isSet;
|
bool m_isSet;
|
||||||
std::unique_ptr<char[]> m_altStackMem;
|
// C++03 doesn't allow auto_ptr<T[]>, so we have manage the memory ourselves
|
||||||
std::array<struct sigaction, sizeof(signalDefs)/sizeof(SignalDefs)> m_oldSigActions;
|
char* m_altStackMem;
|
||||||
|
struct sigaction m_oldSigActions [sizeof(signalDefs)/sizeof(SignalDefs)];
|
||||||
stack_t m_oldSigStack;
|
stack_t m_oldSigStack;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user