diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-05-18 15:51:12 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-05-18 16:30:25 -0400 |
commit | 63a52b1bfc99c58f0a944174282da79aab5bde3a (patch) | |
tree | a31a3cd811ff67313ad72c7d4711ed43a9b050e2 /src/diag.h | |
parent | 24386b8b369dcac60953af3327b75f1870639f5f (diff) | |
download | bfs-63a52b1bfc99c58f0a944174282da79aab5bde3a.tar.xz |
diag: New bfs_verify() and bfs_assert() macros
Diffstat (limited to 'src/diag.h')
-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; /** |