diff options
-rw-r--r-- | src/diag.h | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -46,6 +46,28 @@ noreturn void bfs_abortf(const char *format, ...); # define bfs_bug bfs_abort #endif +/** + * Unconditional assert. + */ +#define bfs_verify(...) \ + BFS_VERIFY(#__VA_ARGS__, __VA_ARGS__, "", "\n") + +#define BFS_VERIFY(str, cond, format, ...) \ + ((cond) ? (void)0 : bfs_abortf( \ + sizeof(format) > 1 \ + ? "%s: %s:%d: %s(): %.0s" format "%s%s" \ + : "%s: %s:%d: %s(): Assertion failed: `%s`%s", \ + BFS_COMMAND, __FILE__, __LINE__, __func__, str, __VA_ARGS__)) + +/** + * Assert in debug builds; no-op in release builds. + */ +#ifdef NDEBUG +# define bfs_assert(...) ((void)0) +#else +# define bfs_assert bfs_verify +#endif + struct bfs_expr; /** |