assert.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "jemalloc/internal/malloc_io.h"
  2. #include "jemalloc/internal/util.h"
  3. /*
  4. * Define a custom assert() in order to reduce the chances of deadlock during
  5. * assertion failure.
  6. */
  7. #ifndef assert
  8. #define assert(e) do { \
  9. if (unlikely(config_debug && !(e))) { \
  10. malloc_printf( \
  11. "<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \
  12. __FILE__, __LINE__, #e); \
  13. abort(); \
  14. } \
  15. } while (0)
  16. #endif
  17. #ifndef not_reached
  18. #define not_reached() do { \
  19. if (config_debug) { \
  20. malloc_printf( \
  21. "<jemalloc>: %s:%d: Unreachable code reached\n", \
  22. __FILE__, __LINE__); \
  23. abort(); \
  24. } \
  25. unreachable(); \
  26. } while (0)
  27. #endif
  28. #ifndef not_implemented
  29. #define not_implemented() do { \
  30. if (config_debug) { \
  31. malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \
  32. __FILE__, __LINE__); \
  33. abort(); \
  34. } \
  35. } while (0)
  36. #endif
  37. #ifndef assert_not_implemented
  38. #define assert_not_implemented(e) do { \
  39. if (unlikely(config_debug && !(e))) { \
  40. not_implemented(); \
  41. } \
  42. } while (0)
  43. #endif
  44. /* Use to assert a particular configuration, e.g., cassert(config_debug). */
  45. #ifndef cassert
  46. #define cassert(c) do { \
  47. if (unlikely(!(c))) { \
  48. not_reached(); \
  49. } \
  50. } while (0)
  51. #endif