2015-07-22 06:11:52 +00:00
|
|
|
// trap.h - written and placed in public domain by Jeffrey Walton.
|
|
|
|
// Copyright assigned to Crypto++ project
|
|
|
|
|
|
|
|
#ifndef CRYPTOPP_TRAP_H
|
|
|
|
#define CRYPTOPP_TRAP_H
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#ifdef CRYPTOPP_UNIX_AVAILABLE
|
|
|
|
# include <iostream>
|
|
|
|
# include <sstream>
|
|
|
|
# include <signal.h>
|
|
|
|
#endif // CRYPTOPP_UNIX_AVAILABLE
|
|
|
|
#endif // NDEBUG
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
// ************** run-time assertion ***************
|
|
|
|
|
2015-07-26 19:26:47 +00:00
|
|
|
// See test.cpp and DebugTrapHandler for code to install a NULL
|
|
|
|
// signal handler for SIGTRAP. The handler installs itself during
|
|
|
|
// initialization of the test program.
|
|
|
|
|
2015-07-22 06:11:52 +00:00
|
|
|
// Linux and Unix
|
|
|
|
#if !defined(NDEBUG) && defined(CRYPTOPP_UNIX_AVAILABLE)
|
|
|
|
# define CRYPTOPP_ASSERT(exp) { \
|
2015-07-30 17:07:33 +00:00
|
|
|
if (!(exp)) { \
|
2015-07-22 06:11:52 +00:00
|
|
|
std::ostringstream oss; \
|
|
|
|
oss << "Assertion failed: " << (char*)(__FILE__) << "(" \
|
|
|
|
<< (int)(__LINE__) << "): " << (char*)(__func__) \
|
|
|
|
<< std::endl; \
|
|
|
|
std::cerr << oss.str(); \
|
|
|
|
raise(SIGTRAP); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
// Fallback to original behavior (including for NDEBUG)
|
|
|
|
#else
|
|
|
|
# define CRYPTOPP_ASSERT(exp) assert(exp)
|
2015-07-26 19:26:47 +00:00
|
|
|
#endif // DEBUG and CRYPTOPP_UNIX_AVAILABLE
|
2015-07-22 06:11:52 +00:00
|
|
|
|
|
|
|
#endif // CRYPTOPP_TRAP_H
|
|
|
|
|