From: Willy Tarreau Date: Fri, 25 Feb 2022 08:10:26 +0000 (+0100) Subject: DEBUG: make the _BUG_ON() macro return the condition X-Git-Tag: v2.6-dev2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a79db30c63e3c07995a9a55a6f0f9ca53d94a977;p=thirdparty%2Fhaproxy.git DEBUG: make the _BUG_ON() macro return the condition By doing so it now becomes an expression and will allow for example to use WARN_ON() in tests, for example: if (WARN_ON(cond)) return NULL; --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index cfd7c9f2ad..9a760c7332 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -52,14 +52,16 @@ /* This is the generic low-level macro dealing with conditional warnings and * bugs. The caller decides whether to crash or not and what prefix and suffix - * to pass. + * to pass. The macro returns the boolean value of the condition as an int for + * the case where it wouldn't die. */ #define _BUG_ON(cond, file, line, crash, pfx, sfx) \ __BUG_ON(cond, file, line, crash, pfx, sfx) #define __BUG_ON(cond, file, line, crash, pfx, sfx) \ - do { \ - if (unlikely(cond)) { \ + ({ \ + int __bug_cond = !!(cond); \ + if (unlikely(__bug_cond)) { \ const char msg[] = "\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n"; \ DISGUISE(write(2, msg, __builtin_strlen(msg))); \ if (crash) \ @@ -67,7 +69,8 @@ else \ DUMP_TRACE(); \ } \ - } while (0) + __bug_cond; /* let's return the condition */ \ + }) /* BUG_ON: complains if is true when DEBUG_STRICT or DEBUG_STRICT_NOCRASH * are set, does nothing otherwise. With DEBUG_STRICT in addition it immediately