]> mj.ucw.cz Git - libucw.git/commitdiff
One more round of changes to the assert code -- I didn't realize that CONFIG_DEBUG
authorMartin Mares <mj@ucw.cz>
Fri, 29 Oct 2004 15:10:21 +0000 (15:10 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 29 Oct 2004 15:10:21 +0000 (15:10 +0000)
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
lib/log.c

index a19128890e27d5915535b5b7ec08c374412b49fe..c2ec50b03d8516ca8f004ec5922a03e9c7a1b51d 100644 (file)
--- 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]
index 4deb75980ab47b8dd01c146069cace478aa728ae..498dba66075c34add409cff54bd92b25eea09cc6 100644 (file)
--- 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)