25 #ifndef __MOTR_LIB_ASSERT_H__ 26 #define __MOTR_LIB_ASSERT_H__ 46 #if defined(GCC_VERSION) && GCC_VERSION < 10000 47 #define M0_GCC_VERSION GCC_VERSION 48 #elif defined(__GNUC__) && defined(__GNUC_MINOR__) 49 #define M0_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 54 #define M0_ASSERT_OFF (1) 56 #define M0_ASSERT_OFF (0) 59 #ifdef ENABLE_EXPENSIVE_CHECKS 60 #define M0_ASSERT_EX_ON (1) 62 #define M0_ASSERT_EX_ON (0) 70 #define likely(x) __builtin_expect(!!(x), 1) 74 #define unlikely(x) __builtin_expect(!!(x), 0) 135 printf_check(const
char *
fmt, ...)
146 #define M0_ASSERT__INIT(msg, fmt, ...) \ 147 static const struct m0_panic_ctx __pctx = { \ 148 msg, __func__, __FILE__, __LINE__, fmt \ 150 printf_check(fmt, ##__VA_ARGS__); \ 151 m0_assert_intercept() 159 #define M0_ASSERT_INFO(cond, fmt, ...) \ 161 M0_ASSERT__INIT(#cond, fmt, ##__VA_ARGS__); \ 162 (M0_ASSERT_OFF || likely(cond) ? \ 163 (void)0 : m0_panic(&__pctx, ##__VA_ARGS__)); \ 167 #define M0_IMPOSSIBLE(fmt, ...) \ 169 M0_ASSERT__INIT("Impossible", "Impossible happened! " fmt, \ 171 m0_panic(&__pctx, ##__VA_ARGS__); \ 185 static inline void m0_assert_intercept(
void) {;}
192 #define M0_ASSERT(cond) M0_ASSERT_INFO((cond), NULL) 199 #define M0_ASSERT_EX(cond) \ 201 if (M0_ASSERT_EX_ON) \ 208 #define M0_ASSERT_INFO_EX(cond, fmt, ...) \ 210 if (M0_ASSERT_EX_ON) \ 211 M0_ASSERT_INFO((cond), (fmt), ##__VA_ARGS__); \ 220 #define M0_PRE(cond) M0_ASSERT(cond) 222 #define M0_PRE_EX(cond) M0_ASSERT_EX(cond) 230 #define M0_POST(cond) M0_ASSERT(cond) 232 #define M0_POST_EX(cond) M0_ASSERT_EX(cond) 237 #define M0_INVARIANT_EX(cond) M0_ASSERT_EX(cond) 245 #define M0_CHECK_EX(cond) (!M0_ASSERT_EX_ON || (cond)) 254 #define M0_CASSERT(cond) do { switch (1) {case 0: case !!(cond): ;} } while (0) 268 #if defined (__cplusplus) && __cplusplus >= 201103L 269 # define M0_BASSERT(cond) static_assert((cond), #cond) 270 #elif defined (M0_GCC_VERSION) && M0_GCC_VERSION >= 4006 271 # define M0_BASSERT(cond) _Static_assert((cond), #cond) 273 # define M0_BASSERT(cond) extern char __static_assertion[(cond) ? 1 : -1] 313 bool __exp = (exp); \ 314 if (!M0_ASSERT_OFF) { \ 316 m0_failed_condition = NULL; \ 318 if (m0_failed_condition == NULL) \ 319 m0_failed_condition = #exp; \ 320 m0__assertion_hook(); \
void m0_panic(const struct m0_panic_ctx *ctx,...)
M0_INTERNAL const char * m0_failed_condition
__attribute__((format(printf, 1, 2))) static inline void printf_check(const char *fmt
M0_INTERNAL void m0_panic_only(const struct m0_panic_ctx *ctx,...)
M0_INTERNAL void m0__assertion_hook(void)
M0_INTERNAL void m0_debugger_invoke(void)
M0_INTERNAL void m0_arch_backtrace(void)
char * fmt(const char *format,...) __attribute__((format(printf
M0_INTERNAL void m0_arch_panic(const struct m0_panic_ctx *ctx, va_list ap) __attribute__((noreturn))