Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

assert.h 1.9KB

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