2018-05-15 02:27:25 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2018-05-15 02:27:25 +02:00
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
2019-07-03 20:00:56 +02:00
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
2018-05-15 02:27:25 +02:00
|
|
|
*/
|
|
|
|
|
2019-01-23 21:10:43 +01:00
|
|
|
#ifndef IGUARD_util_assert_h
|
|
|
|
#define IGUARD_util_assert_h
|
|
|
|
|
2018-05-15 02:27:25 +02:00
|
|
|
#include "taisei.h"
|
|
|
|
|
2019-08-03 18:56:50 +02:00
|
|
|
void _ts_assert_fail(const char *cond, const char *func, const char *file, int line, bool use_log);
|
2018-05-15 02:27:25 +02:00
|
|
|
|
|
|
|
#undef assert
|
|
|
|
#undef static_assert
|
|
|
|
|
|
|
|
#define static_assert _Static_assert
|
2020-08-15 13:51:12 +02:00
|
|
|
#define static_assert_nomsg(x) static_assert(x, #x)
|
2018-05-15 02:27:25 +02:00
|
|
|
|
2019-12-18 14:33:36 +01:00
|
|
|
#if defined(NDEBUG) || defined(__EMSCRIPTEN__)
|
2019-08-03 18:56:50 +02:00
|
|
|
#define TRAP() abort()
|
|
|
|
#elif defined(__clang__)
|
|
|
|
#define TRAP() __builtin_debugtrap()
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
#define TRAP() __builtin_trap()
|
|
|
|
#elif TAISEI_BUILDCONF_HAVE_POSIX
|
|
|
|
#include <signal.h>
|
|
|
|
#define TRAP() raise(SIGTRAP)
|
|
|
|
#else
|
|
|
|
#define TRAP() abort()
|
|
|
|
#endif
|
|
|
|
|
2018-05-15 02:27:25 +02:00
|
|
|
#ifdef NDEBUG
|
2019-02-02 12:25:06 +01:00
|
|
|
#define _assert(cond, uselog)
|
|
|
|
#define _assume(cond, uselog) ASSUME(cond)
|
2018-05-15 02:27:25 +02:00
|
|
|
#else
|
2019-08-03 18:56:50 +02:00
|
|
|
#define _assert(cond, uselog) ((cond) ? (void)0 : (_ts_assert_fail(#cond, __func__, __FILE__, __LINE__, uselog), TRAP()))
|
2019-02-02 12:25:06 +01:00
|
|
|
#define _assume(cond, uselog) _assert(cond, uselog)
|
2018-05-15 02:27:25 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define assert(cond) _assert(cond, true)
|
|
|
|
#define assert_nolog(cond) _assert(cond, false)
|
2019-01-23 21:10:43 +01:00
|
|
|
|
2019-02-02 12:25:06 +01:00
|
|
|
#define assume(cond) _assume(cond, true)
|
|
|
|
#define assume_nolog(cond) _assume(cond, false)
|
|
|
|
|
2019-01-23 21:10:43 +01:00
|
|
|
#endif // IGUARD_util_assert_h
|