2018-02-07 09:19:21 +01:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2018-02-07 09:19:21 +01: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-02-07 09:19:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "assert.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
|
2018-02-07 09:19:21 +01:00
|
|
|
#include "util.h"
|
2018-05-15 02:27:25 +02:00
|
|
|
#include "log.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "util/io.h"
|
2018-02-07 09:19:21 +01:00
|
|
|
|
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
|
|
|
|
) {
|
2019-08-03 18:56:50 +02:00
|
|
|
use_log = use_log && log_initialized();
|
2018-02-07 09:19:21 +01:00
|
|
|
|
2019-08-03 18:56:50 +02:00
|
|
|
if(use_log) {
|
2023-03-26 01:52:41 +01:00
|
|
|
if(msg) {
|
|
|
|
_taisei_log(LOG_FAKEFATAL, func, file, line,
|
|
|
|
"%s:%i: assertion `%s` failed: %s", file, line, cond, msg);
|
|
|
|
} else {
|
|
|
|
_taisei_log(LOG_FAKEFATAL, func, file, line,
|
|
|
|
"%s:%i: assertion `%s` failed", file, line, cond);
|
|
|
|
}
|
|
|
|
|
2023-03-26 01:07:17 +01:00
|
|
|
log_sync(true);
|
2019-08-03 18:56:50 +02:00
|
|
|
} else {
|
2023-03-26 01:52:41 +01:00
|
|
|
if(msg) {
|
|
|
|
tsfprintf(stderr,
|
|
|
|
"%s:%i: %s(): assertion `%s` failed: %s\n", file, line, func, cond, msg);
|
|
|
|
} else {
|
|
|
|
tsfprintf(stderr,
|
|
|
|
"%s:%i: %s(): assertion `%s` failed\n", file, line, func, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
fflush(stderr);
|
2019-08-03 18:56:50 +02:00
|
|
|
}
|
2018-02-07 09:19:21 +01:00
|
|
|
}
|
2021-04-21 03:31:26 +02:00
|
|
|
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
#include <emscripten.h>
|
|
|
|
void _emscripten_trap(void) {
|
2021-08-12 16:12:40 +02:00
|
|
|
EM_ASM({
|
2021-04-21 03:31:26 +02:00
|
|
|
throw new Error("You just activated my trap card!");
|
2021-08-12 16:12:40 +02:00
|
|
|
});
|
2021-04-21 03:31:26 +02:00
|
|
|
}
|
|
|
|
#endif
|