From 5c5ae3962c46cf4051bcd6d4e2355422e63de42b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 3 Mar 2025 16:57:28 -0500 Subject: diag: Get rid of struct bfs_location Just add the standard prefix to the passed format string in the diagnostic macros themselves. This lets us write the whole message with one dprintf() call, minimizing interleaving. It's also a net win for binary size. --- tests/tests.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/tests.h b/tests/tests.h index 4c6b3d2..8b7d691 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -45,26 +45,30 @@ bool bfs_check_impl(bool result); * Check a condition, logging a message on failure but continuing. */ #define bfs_check(...) \ - bfs_check_impl(bfs_check_(#__VA_ARGS__, __VA_ARGS__, "", "")) + bfs_check_(#__VA_ARGS__, __VA_ARGS__, "", ) #define bfs_check_(str, cond, format, ...) \ - ((cond) ? true : (bfs_diag( \ - sizeof(format) > 1 \ - ? "%.0s" format "%s%s" \ - : "Check failed: `%s`%s", \ - str, __VA_ARGS__), false)) + bfs_check_impl((cond) || (bfs_check__(str, format, __VA_ARGS__), false)) + +#define bfs_check__(str, format, ...) \ + bfs_diagf(sizeof(format) > 1 \ + ? BFS_DIAG_FORMAT_("%.0s" format "%s") \ + : BFS_DIAG_FORMAT_("Check failed: `%s`"), \ + BFS_DIAG_ARGS_(str, __VA_ARGS__)) /** * Check a condition, logging the current error string on failure. */ #define bfs_echeck(...) \ - bfs_check_impl(bfs_echeck_(#__VA_ARGS__, __VA_ARGS__, "", errstr())) + bfs_echeck_(#__VA_ARGS__, __VA_ARGS__, "", ) #define bfs_echeck_(str, cond, format, ...) \ - ((cond) ? true : (bfs_diag( \ - sizeof(format) > 1 \ - ? "%.0s" format "%s: %s" \ - : "Check failed: `%s`: %s", \ - str, __VA_ARGS__), false)) + bfs_check_impl((cond) || (bfs_echeck__(str, format, __VA_ARGS__), false)) + +#define bfs_echeck__(str, format, ...) \ + bfs_diagf(sizeof(format) > 1 \ + ? BFS_DIAG_FORMAT_("%.0s" format "%s: %s") \ + : BFS_DIAG_FORMAT_("Check failed: `%s`: %s"), \ + BFS_DIAG_ARGS_(str, __VA_ARGS__ errstr(), )) #endif // BFS_TESTS_H -- cgit v1.2.3