mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 04:14:13 +08:00
mdbx: облегченная assert_fail()
для не-отладочных сборок.
This commit is contained in:
parent
6eeb08de46
commit
c17617b816
@ -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)
|
||||
|
17
src/osal.c
17
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) ? "<troubles with panic-message preparation>"
|
||||
: message;
|
||||
unlikely(num < 1 || !message)
|
||||
? "<troubles with panic-message preparation>"
|
||||
: message;
|
||||
|
||||
if (debug_logger)
|
||||
debug_log(MDBX_LOG_FATAL, "panic", 0, "%s", const_message);
|
||||
|
||||
while (1) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
Loading…
x
Reference in New Issue
Block a user