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.
|
|
|
|
* ---
|
2024-05-16 23:30:41 +02:00
|
|
|
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2024, 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"
|
|
|
|
|
2023-03-26 01:52:41 +01:00
|
|
|
#include "util/macrohax.h"
|
|
|
|
|
2023-03-26 14:06:05 +02:00
|
|
|
#undef static_assert
|
|
|
|
|
|
|
|
#ifdef TAISEI_BUILDCONF_HAVE_STATIC_ASSERT_WITHOUT_MSG
|
|
|
|
#define static_assert _Static_assert
|
|
|
|
#else
|
2023-03-26 01:52:41 +01:00
|
|
|
#define _static_assert_0(cond) _Static_assert(cond, #cond)
|
|
|
|
#define _static_assert_1(cond, msg) _Static_assert(cond, msg)
|
|
|
|
#define static_assert(cond, ...) \
|
|
|
|
MACROHAX_OVERLOAD_NARGS(_static_assert_, __VA_ARGS__)(cond, ##__VA_ARGS__)
|
2021-06-18 15:11:00 +02:00
|
|
|
#endif
|
|
|
|
|
2023-03-26 01:52:41 +01:00
|
|
|
void _ts_assert_fail(
|
|
|
|
const char *cond,
|
|
|
|
const char *msg,
|
|
|
|
const char *func,
|
|
|
|
const char *file,
|
|
|
|
int line,
|
|
|
|
bool use_log
|
|
|
|
);
|
2018-05-15 02:27:25 +02:00
|
|
|
|
|
|
|
#undef assert
|
|
|
|
|
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()
|
|
|
|
#else
|
2023-03-26 03:10:16 +02:00
|
|
|
#define TRAP() __builtin_trap()
|
2019-08-03 18:56:50 +02:00
|
|
|
#endif
|
|
|
|
|
2018-05-15 02:27:25 +02:00
|
|
|
#ifdef NDEBUG
|
2023-03-26 01:52:41 +01:00
|
|
|
#define _assert(cond, msg, uselog)
|
|
|
|
#define _assume(cond, msg, uselog) ASSUME(cond)
|
2018-05-15 02:27:25 +02:00
|
|
|
#else
|
2023-03-26 01:52:41 +01:00
|
|
|
#define _assert(cond, msg, uselog) ({ \
|
|
|
|
if(UNLIKELY(!(cond))) { \
|
|
|
|
_ts_assert_fail(#cond, msg, __func__, _TAISEI_SRC_FILE, __LINE__, uselog); \
|
|
|
|
TRAP(); \
|
|
|
|
} \
|
|
|
|
})
|
|
|
|
#define _assume(cond, msg, uselog) _assert(cond, msg, uselog)
|
2018-05-15 02:27:25 +02:00
|
|
|
#endif
|
|
|
|
|
2023-03-26 01:52:41 +01:00
|
|
|
#define _assert_0(cond) _assert(cond, NULL, true)
|
|
|
|
#define _assert_1(cond, msg) _assert(cond, msg, true)
|
|
|
|
#define assert(cond, ...) \
|
|
|
|
MACROHAX_OVERLOAD_NARGS(_assert_, __VA_ARGS__)(cond, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define _assert_nolog_0(cond) _assert(cond, NULL, false)
|
|
|
|
#define _assert_nolog_1(cond, msg) _assert(cond, msg, false)
|
|
|
|
#define assert_nolog(cond, ...) \
|
|
|
|
MACROHAX_OVERLOAD_NARGS(_assert_nolog_, __VA_ARGS__)(cond, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define _assume_0(cond) _assume(cond, NULL, true)
|
|
|
|
#define _assume_1(cond, msg) _assume(cond, msg, true)
|
|
|
|
#define assume(cond, ...) \
|
|
|
|
MACROHAX_OVERLOAD_NARGS(_assume_, __VA_ARGS__)(cond, ##__VA_ARGS__)
|
2019-01-23 21:10:43 +01:00
|
|
|
|
2023-03-26 01:52:41 +01:00
|
|
|
#define _assume_nolog_0(cond) _assume(cond, NULL, false)
|
|
|
|
#define _assume_nolog_1(cond, msg) _assume(cond, msg, false)
|
|
|
|
#define assume_nolog(cond, ...) \
|
|
|
|
MACROHAX_OVERLOAD_NARGS(_assume_nolog_, __VA_ARGS__)(cond, ##__VA_ARGS__)
|