58 # error Neither DEBUG nor NDEBUG is defined!
62 # error Both DEBUG and NDEBUG are defined - only one should be!
67 #error arb_assert already defined
72 #if defined(DEBUG) && !defined(DEVEL_RELEASE)
78 # define ASSERT_BACKTRACE_AND_STOP
95 #if defined(__cplusplus)
99 #else // !defined(__cplusplus)
100 #define provoke_core_dump() do { *(int*)0 = 0; } while(0)
105 #if defined(SIMPLE_ARB_ASSERT)
109 #define ARB_SIGSEGV(backtrace) do { \
110 provoke_core_dump(); \
113 #define ARB_STOP(backtrace) ARB_SIGSEGV(backtrace)
116 # define arb_assert(cond) \
119 fprintf(stderr, "Assertion '%s' failed in '%s' #%i\n", \
120 #cond, __FILE__, __LINE__); \
121 provoke_core_dump(); \
129 #else // !SIMPLE_ARB_ASSERT
140 #if (GCC_VERSION_CODE>=407) && (GCC_VERSION_CODE<600)
142 # pragma GCC diagnostic push
143 # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
150 #if (GCC_VERSION_CODE>=407) && (GCC_VERSION_CODE<600)
151 # pragma GCC diagnostic pop
154 #define stop_in_debugger() G_BREAKPOINT()
167 #if defined(LEAKS_SANITIZED)
168 # define TRIGGER_SANITIZER() delete ((char*)GBK_getNonfreeableAddress())
169 #else // !LEAKS_SANITIZED
170 # define TRIGGER_SANITIZER()
174 #define ARB_SIGSEGV(backtrace) do { \
175 if (backtrace) GBK_dump_backtrace(NULp, "ARB_SIGSEGV"); \
176 GBK_install_SIGSEGV_handler(false); \
177 TRIGGER_SANITIZER(); \
178 provoke_core_dump(); \
181 #define ARB_STOP(backtrace) \
183 if (backtrace) GBK_dump_backtrace(NULp, "ARB_STOP"); \
184 stop_in_debugger(); \
187 # define arb_assert_crash(cond) \
189 if (!(cond)) ARB_SIGSEGV(0); \
192 # define arb_assert_stop(cond) \
194 if (!(cond)) ARB_STOP(0); \
197 # define arb_assert_backtrace_and_crash(cond) \
200 fputs(GBK_assert_msg(#cond, __FILE__, __LINE__), stderr); \
206 # define arb_assert_backtrace_and_stop(cond) \
209 fputs(GBK_assert_msg(#cond, __FILE__, __LINE__), stderr); \
216 # define arb_assert(cond) arb_assert_crash(cond)
219 # define arb_assert(cond) arb_assert_stop(cond)
221 #ifdef ASSERT_BACKTRACE_AND_CRASH
222 # define arb_assert(cond) arb_assert_backtrace_and_crash(cond)
224 #ifdef ASSERT_BACKTRACE_AND_STOP
225 # define arb_assert(cond) arb_assert_backtrace_and_stop(cond)
228 # define arb_assert(cond) assert_or_exit(cond)
232 # define arb_assert(cond) \
234 fprintf(stderr, "at %s #%i\n", __FILE__, __LINE__); \
235 if (!(cond)) fprintf(stderr, "assertion '%s' failed!\n", #cond); \
240 #endif // SIMPLE_ARB_ASSERT
245 # define arb_assert(cond)
247 # define ASSERTION_USED
251 #undef ASSERT_BACKTRACE_AND_CRASH
253 #undef ASSERT_BACKTRACE_AND_STOP
259 # error arb_assert has not been defined -- check ASSERT_xxx definitions
262 #if !defined(SIMPLE_ARB_ASSERT)
263 #define assert_or_exit(cond) \
266 GBK_terminate(GBK_assert_msg(#cond, __FILE__, __LINE__)); \
269 #endif // SIMPLE_ARB_ASSERT
273 #ifdef UNIT_TESTS // UT_DIFF
274 #ifndef TEST_GLOBAL_H
278 #define RUNNING_TEST() false
289 #define implicated(hypothesis,conclusion) (!(hypothesis) || !!(conclusion))
293 CONSTEXPR_INLINE bool contradicted(
bool hypo1,
bool hypo2) {
return !correlated(hypo1, hypo2); }
300 # define IF_DEBUG(x) x
301 # define IF_NDEBUG(x)
304 # define IF_NDEBUG(x) x
307 #ifdef ASSERTION_USED
308 # define IF_ASSERTION_USED(x) x
310 # define IF_ASSERTION_USED(x)
316 #if defined(ASSERTION_USED)
317 # define ASSERTING_CONSTEXPR_INLINE inline
318 # define ASSERTING_CONSTEXPR_INLINE_Cxx14 inline
319 #else // !ASSERTION_USED
320 # define ASSERTING_CONSTEXPR_INLINE CONSTEXPR_INLINE
321 # define ASSERTING_CONSTEXPR_INLINE_Cxx14 CONSTEXPR_INLINE_Cxx14
334 #ifdef ASSERTION_USED
336 # define ASSERT_RESULT(Type, Expected, Expr) do { \
337 Type value = (Expr); \
338 arb_assert(value == (Expected)); \
341 # define ASSERT_RESULT_PREDICATE(Pred, Expr) do { \
342 arb_assert(Pred(Expr)); \
347 template <
typename T>
inline void dont_warn_unused_result(
T) {}
349 # define ASSERT_RESULT(Type, Expected, Expr) do { \
350 dont_warn_unused_result<Type>(Expr); \
353 # define ASSERT_RESULT_PREDICATE(Pred, Expr) do { \
359 #define ASSERT_NULL_RESULT(ptrExpr) ASSERT_RESULT(const void*, NULp, ptrExpr)
360 #define ASSERT_NO_ERROR(errorExpr) ASSERT_RESULT(GB_ERROR, NULp, errorExpr)
362 #define ASSERT_TRUE(boolExpr) ASSERT_RESULT(bool, true, boolExpr)
363 #define ASSERT_FALSE(boolExpr) ASSERT_RESULT(bool, false, boolExpr)
367 #if defined(ASSERTION_USED)
386 # ifdef ASSERTION_USED
387 # error Assertions enabled in release
393 #if !defined(SIMPLE_ARB_ASSERT)
397 #endif // SIMPLE_ARB_ASSERT
400 #error arb_assert.h included twice
401 #endif // ARB_ASSERT_H
#define implicated(hypothesis, conclusion)
#define provoke_core_dump()
bool knownNonNull(const void *nonnull)