From 9162db31e3341f7ecceab25569e8cb6f91eb99ce Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Mon, 26 Feb 2024 19:09:15 +0100 Subject: [PATCH] add -DBUG_ON -DWARN_ON to enable/disable bug_on()/warn_on() --- Makefile | 3 +++ include/bug.h | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f06dc48..2f717a0 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,9 @@ CPPFLAGS := -I $(INCDIR) CPPFLAGS += -DDEBUG_DEBUG # activate logs funcs CPPFLAGS += -DDEBUG_POOL # mem pools +CPPFLAGS += -DBUG_ON # bug_on in bug.h +CPPFLAGS += -DWARN_ON # warn_on in bug.h + # remove extraneous spaces (due to spaces before comments) CPPFLAGS := $(strip $(CPPFLAGS)) diff --git a/include/bug.h b/include/bug.h index 9f04d54..ab93be7 100644 --- a/include/bug.h +++ b/include/bug.h @@ -16,10 +16,12 @@ #include #include +#include #include #include "likely.h" +#ifdef BUG_ON #define bug_on(expr) do { \ if (unlikely(expr)) { \ fprintf(stderr, \ @@ -28,7 +30,11 @@ abort(); \ } \ } while (0) +#else +#define bug_on(expr) ({ 0; }) +#endif +#ifdef WARN_ON #define warn_on(expr) ({ \ int _ret = !!(expr); \ if (unlikely(_ret)) \ @@ -37,7 +43,9 @@ __func__, __FILE__,__LINE__); \ unlikely(_ret); \ }) - +#else +#define warn_on(expr) ({ 0; }) +#endif #define warn(expr, args...) ({ \ int _ret = !!(expr); \ if (unlikely(_ret)) \