Browse Source

Added assert.h, with assert() defined (almost) as per POSIX, and

linker_assert() defined as gPXE-specific.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
cb8e89de15
1 changed files with 51 additions and 0 deletions
  1. 51
    0
      src/include/assert.h

+ 51
- 0
src/include/assert.h View File

@@ -0,0 +1,51 @@
1
+#ifndef _ASSERT_H
2
+#define _ASSERT_H
3
+
4
+/** @file
5
+ *
6
+ * Assertions
7
+ *
8
+ * This file provides two assertion macros: assert() (for run-time
9
+ * assertions) and linker_assert() (for link-time assertions).
10
+ *
11
+ */
12
+
13
+/**
14
+ * Assert a condition at run-time.
15
+ *
16
+ * If the condition is not true, a debug message will be printed.
17
+ * Assertions only take effect in debug-enabled builds (see DBG()).
18
+ *
19
+ * @todo Make an assertion failure abort the program
20
+ *
21
+ */
22
+#define assert( condition ) 						   \
23
+	do { 								   \
24
+		if ( ! (condition) ) { 					   \
25
+			printf ( "assert(%s) failed at %s line %d [%s]\n", \
26
+				 #condition, __FILE__, __LINE__,	   \
27
+				 __FUNCTION__ );			   \
28
+		} 							   \
29
+	} while ( 0 )
30
+
31
+/**
32
+ * Assert a condition at link-time.
33
+ *
34
+ * If the condition is not true, the link will fail with an unresolved
35
+ * symbol (error_symbol).
36
+ *
37
+ * This macro is gPXE-specific.  Do not use this macro in code
38
+ * intended to be portable.
39
+ *
40
+ */
41
+#define linker_assert( condition, error_symbol )	\
42
+        if ( ! (condition) ) {				\
43
+                extern void error_symbol ( void );	\
44
+                error_symbol();				\
45
+        }
46
+
47
+#ifdef NDEBUG
48
+#undef assert
49
+#define assert(x) do {} while ( 0 )
50
+
51
+#endif /* _ASSERT_H */

Loading…
Cancel
Save