summaryrefslogtreecommitdiffstats
path: root/src/include/assert.h
diff options
context:
space:
mode:
authorMichael Brown2006-12-04 16:09:57 +0100
committerMichael Brown2006-12-04 16:09:57 +0100
commit2e41bfd268e161a45958a8371c321e6c706e0073 (patch)
tree5c209a0b1d5a2a058a8049de8d73c623576fe946 /src/include/assert.h
parentMove ANSI C standard prototypes to stdlib.h; leave the gPXE-specific (diff)
downloadipxe-2e41bfd268e161a45958a8371c321e6c706e0073.tar.gz
ipxe-2e41bfd268e161a45958a8371c321e6c706e0073.tar.xz
ipxe-2e41bfd268e161a45958a8371c321e6c706e0073.zip
Force syntax-checking on assertions even in non-asserting builds.
Diffstat (limited to 'src/include/assert.h')
-rw-r--r--src/include/assert.h32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/include/assert.h b/src/include/assert.h
index b9137fc4..e76ceb97 100644
--- a/src/include/assert.h
+++ b/src/include/assert.h
@@ -10,6 +10,25 @@
*
*/
+#ifdef NDEBUG
+#define ASSERTING 0
+#else
+#define ASSERTING 1
+#endif
+
+/** printf() for assertions
+ *
+ * This function exists so that the assert() macro can expand to
+ * printf() calls without dragging the printf() prototype into scope.
+ *
+ * As far as the compiler is concerned, assert_printf() and printf() are
+ * completely unrelated calls; it's only at the assembly stage that
+ * references to the assert_printf symbol are collapsed into references
+ * to the printf symbol.
+ */
+extern int __attribute__ (( format ( printf, 1, 2 ) ))
+assert_printf ( const char *fmt, ... ) asm ( "printf" );
+
/**
* Assert a condition at run-time.
*
@@ -21,10 +40,10 @@
*/
#define assert( condition ) \
do { \
- if ( ! (condition) ) { \
- printf ( "assert(%s) failed at %s line %d [%s]\n", \
- #condition, __FILE__, __LINE__, \
- __FUNCTION__ ); \
+ if ( ASSERTING && ! (condition) ) { \
+ assert_printf ( "assert(%s) failed at %s line " \
+ "%d [%s]\n", #condition, __FILE__, \
+ __LINE__, __FUNCTION__ ); \
} \
} while ( 0 )
@@ -44,9 +63,4 @@
error_symbol(); \
}
-#ifdef NDEBUG
-#undef assert
-#define assert(x) do {} while ( 0 )
-#endif
-
#endif /* _ASSERT_H */