Pol  Revision:3cfda13
passert.h
Go to the documentation of this file.
1 
11 #ifndef CLIB_PASSERT_H
12 #define CLIB_PASSERT_H
13 
14 #include "compilerspecifics.h"
15 #include <string>
16 
17 #ifndef INC_PASSERT
18 #define INC_PASSERT 0
19 #endif
20 
21 #ifndef INC_PASSERT_PARANOID
22 #ifdef NDEBUG
23 #define INC_PASSERT_PARANOID 0
24 #else
25 #define INC_PASSERT_PARANOID INC_PASSERT
26 #endif
27 #endif
28 namespace Pol
29 {
30 namespace Clib
31 {
32 // what to do on an assertion failure:
33 extern bool passert_dump_stack;
34 extern bool passert_shutdown;
35 extern bool passert_abort;
36 extern bool passert_nosave;
38 
39 extern std::string scripts_thread_script;
40 extern unsigned scripts_thread_scriptPC;
41 
42 //#if !defined(INC_PASSERT) && defined(NDEBUG)
43 //#define INC_PASSERT 0
44 //#elif !defined(INC_PASSERT) && !defined(NDEBUG)
45 //#define INC_PASSERT 1
46 //#endif
47 
48 #undef passert
49 
50 void force_backtrace( bool complete = false );
51 
52 POL_NORETURN void passert_failed( const char* expr, const char* file, unsigned line );
53 POL_NORETURN void passert_failed( const char* expr, const std::string& reason, const char* file,
54  unsigned line );
55 }
56 #if INC_PASSERT
57 
62 #define passert( exp ) \
63  (void)( ( exp ) || ( Clib::passert_failed( #exp, __FILE__, __LINE__ ), 0 ) ); \
64  passert_assume( exp )
65 
66 #define passert_r( exp, reason ) \
67  (void)( ( exp ) || ( Clib::passert_failed( #exp, reason, __FILE__, __LINE__ ), 0 ) ); \
68  passert_assume( exp )
69 
70 #else
71 
72 #define passert( exp ) ( (void)0 )
73 
74 #endif
75 
80 #define passert_always( exp ) \
81  (void)( ( exp ) || ( Clib::passert_failed( #exp, __FILE__, __LINE__ ), 0 ) ); \
82  passert_assume( exp )
83 
84 #define passert_always_r( exp, reason ) \
85  (void)( ( exp ) || ( Clib::passert_failed( #exp, reason, __FILE__, __LINE__ ), 0 ) ); \
86  passert_assume( exp )
87 
88 #if INC_PASSERT_PARANOID
89 
95 #define passert_paranoid( exp ) \
96  (void)( ( exp ) || ( Clib::passert_failed( #exp, __FILE__, __LINE__ ), 0 ) ); \
97  passert_assume( exp )
98 
99 #define passert_paranoid_r( exp, reason ) \
100  (void)( ( exp ) || ( Clib::passert_failed( #exp, reason, __FILE__, __LINE__ ), 0 ) ); \
101  passert_assume( exp )
102 
103 #else
104 
105 #define passert_paranoid( exp ) ( (void)0 )
106 
107 #endif
108 }
109 #endif
std::string scripts_thread_script
Definition: passert.cpp:36
bool passert_shutdown
Definition: passert.cpp:31
void force_backtrace(bool complete)
Definition: passert.cpp:53
bool passert_dump_stack
Definition: passert.cpp:30
#define POL_NORETURN
bool passert_nosave
Definition: passert.cpp:33
bool passert_shutdown_due_to_assertion
Definition: passert.cpp:34
void passert_failed(const char *expr, const char *file, unsigned line)
Definition: passert.cpp:65
Definition: berror.cpp:12
bool passert_abort
Definition: passert.cpp:32
unsigned scripts_thread_scriptPC
Definition: passert.cpp:37