Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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