From 63a52b1bfc99c58f0a944174282da79aab5bde3a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 18 May 2023 15:51:12 -0400 Subject: diag: New bfs_verify() and bfs_assert() macros --- src/diag.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/diag.h b/src/diag.h index a3e0e1d..71abb1a 100644 --- a/src/diag.h +++ b/src/diag.h @@ -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; /** -- cgit v1.2.3