From 7bedfddfba09e9f93615fee2623d44a9d0e1a605 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sat, 18 May 2024 13:30:46 +0200 Subject: [PATCH] allow bug.h re-inclusion --- include/bug.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/include/bug.h b/include/bug.h index ab93be7..b4b2329 100644 --- a/include/bug.h +++ b/include/bug.h @@ -11,8 +11,21 @@ * */ -#ifndef _BUG_H -#define _BUG_H +/* we allow multiple inclusions, so that BUG_ON/WARN_ON can change during + * compilation. + */ +#ifdef BUG_H + +#undef BUG_H + +/* reset all macros */ +#undef bug_on +#undef warn_on +#undef warn + +#endif /* BUG_H */ + +#define BUG_H #include #include @@ -22,7 +35,7 @@ #include "likely.h" #ifdef BUG_ON -#define bug_on(expr) do { \ +#define bug_on(expr) do { \ if (unlikely(expr)) { \ fprintf(stderr, \ "** BUG IN %s[%s:%d]: assertion \"" #expr "\" failed.\n", \ @@ -31,7 +44,7 @@ } \ } while (0) #else -#define bug_on(expr) ({ 0; }) +#define bug_on(expr) #endif #ifdef WARN_ON @@ -46,11 +59,10 @@ #else #define warn_on(expr) ({ 0; }) #endif + #define warn(expr, args...) ({ \ int _ret = !!(expr); \ if (unlikely(_ret)) \ fprintf(stderr, ##args); \ unlikely(_ret); \ }) - -#endif /* _BUG_H */