From fc078dbe4fe9653bee78853f0cbefc5b79c322a6 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 20 Aug 2002 19:04:54 +0000 Subject: [PATCH] If not debugging, compile at least ASSERT(0) as call to an unreachable function. (Avoid unassigned variable warnings.) --- lib/lib.h | 5 +++-- lib/log.c | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/lib.h b/lib/lib.h index ad19f505..c1709ea2 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -50,15 +50,16 @@ void log(unsigned int cat, const char *msg, ...) __attribute__((format(printf,2,3))); void die(byte *, ...) NONRET; -void assert_failed(char *assertion, char *file, int line) NONRET; void log_init(byte *); void log_file(byte *); void log_fork(void); #ifdef DEBUG +void assert_failed(char *assertion, char *file, int line) NONRET; #define ASSERT(x) do { if (!(x)) assert_failed(#x, __FILE__, __LINE__); } while(0) #else -#define ASSERT(x) do { } while(0) +void assert_failed(void) NONRET; +#define ASSERT(x) do { if (__builtin_constant_p(x) && !(x)) assert_failed(); } while(0) #endif #ifdef LOCAL_DEBUG diff --git a/lib/log.c b/lib/log.c index e25476b6..bcbce64b 100644 --- a/lib/log.c +++ b/lib/log.c @@ -96,12 +96,20 @@ die(byte *msg, ...) exit(1); } +#ifdef 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) +{ + die("Internal error: Assertion failed."); +} +#endif static byte * log_basename(byte *n) -- 2.39.5