From c70b0bd774606177c893f6869ece09d0fd1d9034 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 29 Oct 2004 15:10:21 +0000 Subject: [PATCH] One more round of changes to the assert code -- I didn't realize that CONFIG_DEBUG is already used to control compilation of debugging utilities. Introduced DEBUG_ASSERTS as a separate switch and as a bonus, you can use assertions selectively (previously, if you have built the library without assertions, ASSERT couldn't work anywhere, because assert_failed() was incompatible). --- lib/lib.h | 7 ++++--- lib/log.c | 6 ++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/lib.h b/lib/lib.h index a1912889..c2ec50b0 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -71,12 +71,13 @@ void log_file(byte *name); void log_fork(void); void log_switch(void); -#ifdef CONFIG_DEBUG void assert_failed(char *assertion, char *file, int line) NONRET; +void assert_failed_noinfo(void) NONRET; + +#ifdef DEBUG_ASSERTS #define ASSERT(x) do { if (unlikely(!(x))) assert_failed(#x, __FILE__, __LINE__); } while(0) #else -void assert_failed(void) NONRET; -#define ASSERT(x) do { if (__builtin_constant_p(x) && !(x)) assert_failed(); } while(0) +#define ASSERT(x) do { if (__builtin_constant_p(x) && !(x)) assert_failed_noinfo(); } while(0) #endif #define COMPILE_ASSERT(name,x) typedef char _COMPILE_ASSERT_##name[!!(x)-1] diff --git a/lib/log.c b/lib/log.c index 4deb7598..498dba66 100644 --- a/lib/log.c +++ b/lib/log.c @@ -99,20 +99,18 @@ die(byte *msg, ...) #endif } -#ifdef CONFIG_DEBUG void assert_failed(char *assertion, char *file, int line) { log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line); abort(); } -#else + void -assert_failed(void) +assert_failed_noinfo(void) { die("Internal error: Assertion failed."); } -#endif static byte * log_basename(byte *n) -- 2.39.2