From: terencehill Date: Sat, 9 Feb 2019 18:45:25 +0000 (+0100) Subject: Use a function to print the assertion failed message (server: qc -380KB, dat -190KB... X-Git-Tag: xonotic-v0.8.5~1604^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1316f5675cfb765314120ebd5a59a15ff9dac00a;p=xonotic%2Fxonotic-data.pk3dir.git Use a function to print the assertion failed message (server: qc -380KB, dat -190KB, globals -800) --- diff --git a/qcsrc/lib/log.qh b/qcsrc/lib/log.qh index b751bfb2a..4b4f7b6bd 100644 --- a/qcsrc/lib/log.qh +++ b/qcsrc/lib/log.qh @@ -2,7 +2,10 @@ #include "progname.qh" -#define assert(expr, ...) _assert(LOG_SEVERE, expr, __VA_ARGS__) +void print_assertfailed_severe(string expr); +void print_assertfailed_fatal(string expr); + +#define assert(expr, ...) _assert(print_assertfailed_severe, expr, __VA_ARGS__) #define devassert(...) MACRO_BEGIN if (autocvar_developer) assert(__VA_ARGS__); MACRO_END #define assert_once(expr, ...) \ @@ -16,14 +19,14 @@ MACRO_END #define devassert_once(...) MACRO_BEGIN if (autocvar_developer) assert_once(__VA_ARGS__); MACRO_END -#define demand(expr, ...) _assert(LOG_FATAL, expr, __VA_ARGS__) +#define demand(expr, ...) _assert(print_assertfailed_fatal, expr, __VA_ARGS__) #define devdemand(...) MACRO_BEGIN if (autocvar_developer) demand(__VA_ARGS__); MACRO_END #define _assert(f, expr, then) \ MACRO_BEGIN \ if (!(expr)) \ { \ - f("assertion failed: `" #expr "`\n"); \ + f(#expr); \ then; \ } \ MACRO_END @@ -111,3 +114,15 @@ noref bool autocvar_prvm_backtraceforwarnings; bt_cvar_set("developer", ftos(dev)); \ bt_cvar_set("prvm_backtraceforwarnings", ftos(war)); \ MACRO_END + +void print_assertfailed_severe(string expr) +{ + // this is inside a function to avoid expanding it on compilation everytime + LOG_SEVERE("assertion failed: `", expr, "`\n"); +} + +void print_assertfailed_fatal(string expr) +{ + // this is inside a function to avoid expanding it on compilation everytime + LOG_FATAL("assertion failed: `", expr, "`\n"); +}