summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-05-18 15:51:12 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-05-18 16:30:25 -0400
commit63a52b1bfc99c58f0a944174282da79aab5bde3a (patch)
treea31a3cd811ff67313ad72c7d4711ed43a9b050e2 /src
parent24386b8b369dcac60953af3327b75f1870639f5f (diff)
downloadbfs-63a52b1bfc99c58f0a944174282da79aab5bde3a.tar.xz
diag: New bfs_verify() and bfs_assert() macros
Diffstat (limited to 'src')
-rw-r--r--src/diag.h22
1 files changed, 22 insertions, 0 deletions
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;
/**