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
|
|
|
*/
|
|
|
|
|
2021-08-12 23:09:01 +02:00
|
|
|
#pragma once
|
2018-05-15 02:27:25 +02:00
|
|
|
#include "taisei.h"
|
|
|
|
|
2021-06-18 15:11:00 +02:00
|
|
|
#if __has_attribute(analyzer_noreturn)
|
|
|
|
#define attr_analyzer_noreturn \
|
|
|
|
__attribute__ ((analyzer_noreturn))
|
|
|
|
#else
|
|
|
|
#define attr_analyzer_noreturn
|
|
|
|
#endif
|
|
|
|
|
|
|
|
attr_analyzer_noreturn
|
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
|
|
|
|
2021-04-21 03:31:26 +02:00
|
|
|
#if defined(__EMSCRIPTEN__)
|
|
|
|
void _emscripten_trap(void);
|
|
|
|
#define TRAP() _emscripten_trap()
|
|
|
|
#elif defined(NDEBUG)
|
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
|
2022-09-01 05:50:55 +02:00
|
|
|
#define _assert(cond, uselog) (LIKELY(cond) ? (void)0 : (_ts_assert_fail(#cond, __func__, _TAISEI_SRC_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)
|