Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / assert.h
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 FILE_LICENCE ( GPL2_OR_LATER );
14
15 #ifdef NDEBUG
16 #define ASSERTING 0
17 #else
18 #define ASSERTING 1
19 #endif
20
21 extern unsigned int assertion_failures;
22
23 #define ASSERTED ( ASSERTING && ( assertion_failures != 0 ) )
24
25 /** printf() for assertions
26  *
27  * This function exists so that the assert() macro can expand to
28  * printf() calls without dragging the printf() prototype into scope.
29  *
30  * As far as the compiler is concerned, assert_printf() and printf() are
31  * completely unrelated calls; it's only at the assembly stage that
32  * references to the assert_printf symbol are collapsed into references
33  * to the printf symbol.
34  */
35 extern int __attribute__ (( format ( printf, 1, 2 ) )) 
36 assert_printf ( const char *fmt, ... ) asm ( "printf" );
37
38 /**
39  * Assert a condition at run-time.
40  *
41  * If the condition is not true, a debug message will be printed.
42  * Assertions only take effect in debug-enabled builds (see DBG()).
43  *
44  * @todo Make an assertion failure abort the program
45  *
46  */
47 #define assert( condition )                                                  \
48         do {                                                                 \
49                 if ( ASSERTING && ! (condition) ) {                          \
50                         assertion_failures++;                                \
51                         assert_printf ( "assert(%s) failed at %s line %d\n", \
52                                         #condition, __FILE__, __LINE__ );    \
53                 }                                                            \
54         } while ( 0 )
55
56 /**
57  * Assert a condition at link-time.
58  *
59  * If the condition is not true, the link will fail with an unresolved
60  * symbol (error_symbol).
61  *
62  * This macro is iPXE-specific.  Do not use this macro in code
63  * intended to be portable.
64  *
65  */
66 #define linker_assert( condition, error_symbol )        \
67         if ( ! (condition) ) {                          \
68                 extern void error_symbol ( void );      \
69                 error_symbol();                         \
70         }
71
72 #endif /* _ASSERT_H */