Skip to content

Commit

Permalink
Implements assertion macros with source file information overrides.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Apr 10, 2022
1 parent 391c9d5 commit bed16af
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion src/debug/asserthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,86 @@ void Vinifera_Assert(AssertType type, const char *expr, const char *file, int li
} \
} \
} \
} while (false)
} while (false)


/**
* Assertion macros for overriding source information.
*/
#define ASSERT_CUSTOM(exp, file, line, func) \
do { \
static volatile bool _ignore_assert = false; \
static volatile bool _break = false; \
static volatile bool _exit = false; \
if (!IgnoreAllAsserts) { \
if (!_ignore_assert) { \
if (!(exp)) { \
Vinifera_Assert(ASSERT_NORMAL, #exp, file, line, func, &_ignore_assert, &_break, &_exit, nullptr); \
if (_break) { \
__debugbreak(); \
} \
if (_exit || ExitOnAssert) { \
Emergency_Exit(EXIT_FAILURE); \
} \
} \
} \
} \
} while (false)

#define ASSERT_CUSTOM_FATAL(exp, file, line, func) \
do { \
static volatile bool _ignore_assert = false; \
static volatile bool _break = false; \
static volatile bool _exit = false; \
if (!IgnoreAllAsserts) { \
if (!_ignore_assert) { \
if (!(exp)) { \
Vinifera_Assert(ASSERT_NORMAL, #exp, file, line, func, &_ignore_assert, &_break, &_exit, nullptr); \
if (_break) { \
__debugbreak(); \
} \
if (_exit || ExitOnAssert) { \
Emergency_Exit(EXIT_FAILURE); \
} \
} \
} \
} \
} while (false)

#define ASSERT_CUSTOM_PRINT(exp, file, line, func, msg, ...) \
do { \
static volatile bool _ignore_assert = false; \
static volatile bool _break = false; \
static volatile bool _exit = false; \
if (!IgnoreAllAsserts) { \
if (!_ignore_assert) { \
if (!(exp)) { \
Vinifera_Assert(ASSERT_NORMAL, #exp, file, line, func, &_ignore_assert, &_break, &_exit, msg, ##__VA_ARGS__); \
if (_break) { \
__debugbreak(); \
} \
if (_exit || ExitOnAssert) { \
Emergency_Exit(EXIT_FAILURE); \
} \
} \
} \
} \
} while (false)

#define ASSERT_CUSTOM_PRINT_FATAL(exp, file, line, func, msg, ...) \
do { \
static volatile bool _ignore_assert = false; \
static volatile bool _break = false; \
static volatile bool _exit = false; \
if (!IgnoreAllAsserts) { \
if (!_ignore_assert) { \
if (!(exp)) { \
Vinifera_Assert(ASSERT_NORMAL, #exp, file, line, func, &_ignore_assert, &_break, &_exit, msg, ##__VA_ARGS__); \
if (_break) { \
__debugbreak(); \
} \
Emergency_Exit(EXIT_FAILURE); \
} \
} \
} \
} while (false)

0 comments on commit bed16af

Please sign in to comment.