allow bug.h re-inclusion

This commit is contained in:
2024-05-18 13:30:46 +02:00
parent 8ff163dcf5
commit 7bedfddfba

View File

@@ -11,8 +11,21 @@
* *
*/ */
#ifndef _BUG_H /* we allow multiple inclusions, so that BUG_ON/WARN_ON can change during
#define _BUG_H * 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 <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -22,7 +35,7 @@
#include "likely.h" #include "likely.h"
#ifdef BUG_ON #ifdef BUG_ON
#define bug_on(expr) do { \ #define bug_on(expr) do { \
if (unlikely(expr)) { \ if (unlikely(expr)) { \
fprintf(stderr, \ fprintf(stderr, \
"** BUG IN %s[%s:%d]: assertion \"" #expr "\" failed.\n", \ "** BUG IN %s[%s:%d]: assertion \"" #expr "\" failed.\n", \
@@ -31,7 +44,7 @@
} \ } \
} while (0) } while (0)
#else #else
#define bug_on(expr) ({ 0; }) #define bug_on(expr)
#endif #endif
#ifdef WARN_ON #ifdef WARN_ON
@@ -46,11 +59,10 @@
#else #else
#define warn_on(expr) ({ 0; }) #define warn_on(expr) ({ 0; })
#endif #endif
#define warn(expr, args...) ({ \ #define warn(expr, args...) ({ \
int _ret = !!(expr); \ int _ret = !!(expr); \
if (unlikely(_ret)) \ if (unlikely(_ret)) \
fprintf(stderr, ##args); \ fprintf(stderr, ##args); \
unlikely(_ret); \ unlikely(_ret); \
}) })
#endif /* _BUG_H */