diff --git a/src/internals.h b/src/internals.h index 859a41c0..8af9dde2 100644 --- a/src/internals.h +++ b/src/internals.h @@ -1368,10 +1368,22 @@ MDBX_INTERNAL_FUNC void debug_log_va(int level, const char *function, int line, #define FATAL(fmt, ...) \ debug_log(MDBX_LOG_FATAL, __func__, __LINE__, fmt "\n", __VA_ARGS__); +#if MDBX_DEBUG +#define ASSERT_FAIL(env, msg, func, line) mdbx_assert_fail(env, msg, func, line) +#else /* MDBX_DEBUG */ +MDBX_NORETURN __cold void assert_fail(const char *msg, const char *func, + unsigned line); +#define ASSERT_FAIL(env, msg, func, line) \ + do { \ + (void)(env); \ + assert_fail(msg, func, line); \ + } while (0) +#endif /* MDBX_DEBUG */ + #define ENSURE_MSG(env, expr, msg) \ do { \ if (unlikely(!(expr))) \ - mdbx_assert_fail(env, msg, __func__, __LINE__); \ + ASSERT_FAIL(env, msg, __func__, __LINE__); \ } while (0) #define ENSURE(env, expr) ENSURE_MSG(env, expr, #expr) diff --git a/src/osal.c b/src/osal.c index f8600cb8..6a2697fa 100644 --- a/src/osal.c +++ b/src/osal.c @@ -224,12 +224,15 @@ __extern_C void __assert(const char *function, const char *file, int line, __cold void mdbx_assert_fail(const MDBX_env *env, const char *msg, const char *func, unsigned line) { #if MDBX_DEBUG - if (env && env->me_assert_func) { + if (env && env->me_assert_func) env->me_assert_func(env, msg, func, line); - return; - } #else (void)env; + assert_fail(msg, func, line); +} + +MDBX_NORETURN __cold void assert_fail(const char *msg, const char *func, + unsigned line) { #endif /* MDBX_DEBUG */ if (debug_logger) @@ -266,8 +269,12 @@ __cold void mdbx_panic(const char *fmt, ...) { const int num = osal_vasprintf(&message, fmt, ap); va_end(ap); const char *const const_message = - (num < 1 || !message) ? "" - : message; + unlikely(num < 1 || !message) + ? "" + : message; + + if (debug_logger) + debug_log(MDBX_LOG_FATAL, "panic", 0, "%s", const_message); while (1) { #if defined(_WIN32) || defined(_WIN64)