Skip to content

Commit f3da35b

Browse files
committed
mdbx: osal_safe_peek_uint32() implementation.
2026-03-31 mdbx: osal_safe_peek_uint32() implementation. 2026-03-31 mdbx: add mdbx_assert_fail() and refine MDBX_INLINE_API_ASSERT(). 2026-03-31 mdbx-api: move LIKELY/UNLIKELY macros.
1 parent 80077d0 commit f3da35b

14 files changed

Lines changed: 91 additions & 54 deletions

VERSION.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "git_describe": "v0.14.1-521-gb2ff247e", "git_timestamp": "2026-03-30T18:07:04+03:00", "git_tree": "1e32d4c79f8feb451e687c4e4e323deaf7723e11", "git_commit": "b2ff247e2e49c93b3ff78f5a9e2eab260d2a89d1", "semver": "0.14.1.521" }
1+
{ "git_describe": "v0.14.1-524-gba1be46d", "git_timestamp": "2026-03-31T02:48:49+03:00", "git_tree": "532377bcb1496286a8b1017c6117dba576fd559c", "git_commit": "ba1be46d6b6742802ec4ecde52ba6569eb81724b", "semver": "0.14.1.524" }

config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00),
1+
/* This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00),
22
* it is the template for libmdbx's config.h
33
******************************************************************************/
44

mdbx-internals.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00).
1+
/* This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00).
22
*
33
* libmdbx (aka MDBX) is an extremely fast, compact, powerful, embeddedable, transactional key-value storage engine with
44
* open-source code. MDBX has a specific set of properties and capabilities, focused on creating unique lightweight
@@ -24,7 +24,7 @@
2424

2525
#define xMDBX_ALLOY 1 /* alloyed build */
2626

27-
#define MDBX_BUILD_SOURCERY dd6dc4dddf390f4be49005e8dac1a89625c8902afb2bc1838666815bed5e24cf_v0_14_1_521_gb2ff247e
27+
#define MDBX_BUILD_SOURCERY 9169e20f7f7159fe1eb0c5248433ae0dde0cfc1a51469b0fd7daea9f9555d48e_v0_14_1_524_gba1be46d
2828

2929
#define LIBMDBX_INTERNALS
3030
#define MDBX_DEPRECATED
@@ -1654,6 +1654,8 @@ MDBX_INTERNAL int osal_mb2w(const char *const src, wchar_t **const pdst);
16541654

16551655
MDBX_INTERNAL bin128_t osal_guid(const MDBX_env *);
16561656

1657+
MDBX_INTERNAL bool osal_safe_peek_uint32(const void *ptr, int32_t *dest);
1658+
16571659
/*----------------------------------------------------------------------------*/
16581660

16591661
MDBX_MAYBE_UNUSED MDBX_NOTHROW_PURE_FUNCTION static inline uint64_t osal_bswap64(uint64_t v) {

mdbx.c

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00).
1+
/* This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00).
22
*
33
* libmdbx (aka MDBX) is an extremely fast, compact, powerful, embeddedable, transactional key-value storage engine with
44
* open-source code. MDBX has a specific set of properties and capabilities, focused on creating unique lightweight
@@ -26474,19 +26474,12 @@ __cold void page_list(page_t *mp) {
2647426474

2647526475
#if MDBX_CHECKING >= 0
2647626476

26477-
static bool osal_safe_read_uint32(const void *ptr, int32_t *dest) {
26478-
*dest = 0;
26479-
/* TODO: FIXME */
26480-
(void)ptr;
26481-
return false;
26482-
}
26483-
2648426477
__cold const char *object2class(const void *ptr) {
2648526478
if (!ptr)
2648626479
return "null";
2648726480

2648826481
int32_t snap_signature = 0;
26489-
if (!osal_safe_read_uint32(ptr, &snap_signature))
26482+
if (!osal_safe_peek_uint32(ptr, &snap_signature))
2649026483
return "bad";
2649126484

2649226485
switch (snap_signature) {
@@ -26505,7 +26498,7 @@ __cold const char *object2class(const void *ptr) {
2650526498
return "unknown";
2650626499
}
2650726500

26508-
MDBX_NORETURN static void panic_kick(const char *msg, const char *func, unsigned line, const void *obj) {
26501+
MDBX_NORETURN static void fuckup(const char *msg, const char *func, unsigned line, const void *obj) {
2650926502
const char *obj_class = object2class(obj);
2651026503
MDBX_DTRACE5(panic, func, line, msg, obj_class, obj);
2651126504
const MDBX_panic_func panic_func = globals.panic_func;
@@ -26516,7 +26509,7 @@ MDBX_NORETURN static void panic_kick(const char *msg, const char *func, unsigned
2651626509
}
2651726510

2651826511
__cold __noinline void panic_at_obj(const struct MDBX_panic_point *const at, const void *obj) {
26519-
panic_kick(at->msg, at->function, at->line, obj);
26512+
fuckup(at->msg, at->function, at->line, obj);
2652026513
}
2652126514

2652226515
__cold __noinline void panic_at(const struct MDBX_panic_point *const at) { panic_at_obj(at, nullptr); }
@@ -26527,9 +26520,11 @@ __cold __noinline void panic_at_fmt(const struct MDBX_panic_point *const at, con
2652726520
char *message = nullptr;
2652826521
const int num = osal_vasprintf(&message, obj, ap);
2652926522
const char *const const_message = unlikely(num < 1 || !message) ? "<vasprintf() failed>" : message;
26530-
panic_kick(const_message, at->function, at->line, obj);
26523+
fuckup(const_message, at->function, at->line, obj);
2653126524
}
2653226525

26526+
__cold void mdbx_assert_fail(const char *msg, const char *func, unsigned line) { fuckup(msg, func, line, nullptr); }
26527+
2653326528
#endif /* MDBX_CHECKING >= 0 */
2653426529

2653526530
typedef struct meta_snap {
@@ -29036,6 +29031,10 @@ bool osal_pathequal(const pathchar_t *l, const pathchar_t *r, size_t len) {
2903629031
#endif
2903729032
}
2903829033

29034+
#if !(defined(_WIN32) || defined(_WIN64))
29035+
static const char dev_null[] = "/dev/null";
29036+
#endif /* !Windows */
29037+
2903929038
int osal_openfile(const enum osal_openfile_purpose purpose, const MDBX_env *env, const pathchar_t *pathname,
2904029039
mdbx_filehandle_t *fd, mdbx_mode_t unix_mode_bits) {
2904129040
*fd = INVALID_HANDLE_VALUE;
@@ -29163,7 +29162,6 @@ int osal_openfile(const enum osal_openfile_purpose purpose, const MDBX_env *env,
2916329162
/* Safeguard for https://libmdbx.dqdkfa.ru/dead-github/issues/144 */
2916429163
#if STDIN_FILENO == 0 && STDOUT_FILENO == 1 && STDERR_FILENO == 2
2916529164
int stub_fd0 = -1, stub_fd1 = -1, stub_fd2 = -1;
29166-
static const char dev_null[] = "/dev/null";
2916729165
if (!is_valid_fd(STDIN_FILENO)) {
2916829166
WARNING("STD%s_FILENO/%d is invalid, open %s for temporary stub", "IN", STDIN_FILENO, dev_null);
2916929167
stub_fd0 = open(dev_null, O_RDONLY | O_NOCTTY);
@@ -31385,6 +31383,36 @@ const char *osal_getenv(const char *name, bool secure) {
3138531383
#endif
3138631384
}
3138731385

31386+
bool osal_safe_peek_uint32(const void *ptr, int32_t *dest) {
31387+
bool done = false;
31388+
*dest = 0;
31389+
#if defined(_WIN32) || defined(_WIN64)
31390+
__try {
31391+
if (IsBadReadPtr(ptr, 4) == 0) {
31392+
memcpy(dest, ptr, 4);
31393+
done = true;
31394+
}
31395+
} __except (EXCEPTION_EXECUTE_HANDLER) {
31396+
return false;
31397+
;
31398+
}
31399+
#else
31400+
static int nullfd = -1;
31401+
if (nullfd < 0) {
31402+
nullfd = open(dev_null, O_WRONLY
31403+
#ifdef O_CLOEXEC
31404+
| O_CLOEXEC
31405+
#endif /* O_CLOEXEC */
31406+
);
31407+
}
31408+
if (write(nullfd, ptr, 4) == 4) {
31409+
memcpy(dest, ptr, 4);
31410+
done = true;
31411+
}
31412+
#endif
31413+
return done;
31414+
}
31415+
3138831416
/*--------------------------------------------------------------------------*/
3138931417

3139031418
void osal_ctor(void) {
@@ -40227,10 +40255,10 @@ __dll_export
4022740255
0,
4022840256
14,
4022940257
1,
40230-
521,
40258+
524,
4023140259
"", /* pre-release suffix of SemVer
40232-
0.14.1.521 */
40233-
{"2026-03-30T18:07:04+03:00", "1e32d4c79f8feb451e687c4e4e323deaf7723e11", "b2ff247e2e49c93b3ff78f5a9e2eab260d2a89d1", "v0.14.1-521-gb2ff247e"},
40260+
0.14.1.524 */
40261+
{"2026-03-31T02:48:49+03:00", "532377bcb1496286a8b1017c6117dba576fd559c", "ba1be46d6b6742802ec4ecde52ba6569eb81724b", "v0.14.1-524-gba1be46d"},
4023440262
sourcery};
4023540263

4023640264
__dll_export

mdbx.c++

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00).
1+
/* This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00).
22
*
33
* libmdbx (aka MDBX) is an extremely fast, compact, powerful, embeddedable, transactional key-value storage engine with
44
* open-source code. MDBX has a specific set of properties and capabilities, focused on creating unique lightweight

mdbx.h

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00).
1+
/** This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00).
22
33
\file mdbx.h
44
\brief The libmdbx C API header file.
@@ -585,6 +585,34 @@ typedef mode_t mdbx_mode_t;
585585

586586
#endif /* DEFINE_ENUM_FLAG_OPERATORS */
587587

588+
#ifndef MDBX_LIKELY
589+
#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
590+
#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
591+
#else
592+
#define MDBX_LIKELY(x) (x)
593+
#endif
594+
#endif /* MDBX_LIKELY */
595+
596+
#ifndef MDBX_UNLIKELY
597+
#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
598+
#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
599+
#else
600+
#define MDBX_UNLIKELY(x) (x)
601+
#endif
602+
#endif /* MDBX_UNLIKELY */
603+
604+
#if defined(DOXYGEN) || (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
605+
#define MDBX_INLINE_API_ASSERT(expr) \
606+
do { \
607+
if (MDBX_UNLIKELY(!(expr))) \
608+
mdbx_assert_fail(#expr, __func__, __LINE__); \
609+
} while (0)
610+
#else
611+
/* clang-format off */
612+
#define MDBX_INLINE_API_ASSERT(expr) do {} while(0)
613+
/* clang-format on */
614+
#endif /* MDBX_INLINE_API_ASSERT */
615+
588616
/** end of api_macros @} */
589617

590618
/*----------------------------------------------------------------------------*/
@@ -703,14 +731,6 @@ void LIBMDBX_API NTAPI mdbx_module_handler(PVOID module, DWORD reason, PVOID res
703731

704732
#endif /* Windows && !DLL && MDBX_MANUAL_MODULE_HANDLER */
705733

706-
#if (defined(MDBX_CHECKING) && MDBX_CHECKING > 0) || (defined(MDBX_DEBUG) && MDBX_DEBUG > 0)
707-
#define MDBX_INLINE_API_ASSERT(expr) assert(expr)
708-
#else
709-
/* clang-format off */
710-
#define MDBX_INLINE_API_ASSERT(expr) do {} while(0)
711-
/* clang-format on */
712-
#endif /* MDBX_INLINE_API_ASSERT */
713-
714734
/* OPACITY STRUCTURES *********************************************************/
715735

716736
/** \brief Opaque structure for a database environment.
@@ -1010,6 +1030,9 @@ LIBMDBX_API int mdbx_setup_debug_nofmt(MDBX_log_level_t log_level, MDBX_debug_fl
10101030
typedef void (*MDBX_panic_func)(const char *msg, const char *function, unsigned line, const void *obj,
10111031
const char *obj_class) MDBX_CXX17_NOEXCEPT;
10121032

1033+
/** \brief Auxiliary function for MDBX_INLINE_API_ASSERT(). */
1034+
MDBX_NORETURN LIBMDBX_API void mdbx_assert_fail(const char *msg, const char *func, unsigned line);
1035+
10131036
/** \brief Sets or reset the callback for panic() and assert() for the current process.
10141037
*
10151038
* \param [in] func An MDBX_assert_func function, or 0. */

mdbx.h++

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00).
1+
/// This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00).
22
/// \file mdbx.h++
33
/// \brief The libmdbx C++ API header file.
44
///
@@ -220,22 +220,6 @@
220220
#define MDBX_CONSTEXPR_ASSERT(expr) ((expr) ? void(0) : [] { assert(!#expr); }())
221221
#endif /* MDBX_CONSTEXPR_ASSERT */
222222

223-
#ifndef MDBX_LIKELY
224-
#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
225-
#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
226-
#else
227-
#define MDBX_LIKELY(x) (x)
228-
#endif
229-
#endif /* MDBX_LIKELY */
230-
231-
#ifndef MDBX_UNLIKELY
232-
#if defined(DOXYGEN) || (defined(__GNUC__) || __has_builtin(__builtin_expect)) && !defined(__COVERITY__)
233-
#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
234-
#else
235-
#define MDBX_UNLIKELY(x) (x)
236-
#endif
237-
#endif /* MDBX_UNLIKELY */
238-
239223
/** Workaround for old compilers without properly support for C++20 `if constexpr`. */
240224
#if defined(DOXYGEN)
241225
#define MDBX_IF_CONSTEXPR constexpr

mdbx_chk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00).
1+
/* This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00).
22
*
33
* libmdbx (aka MDBX) is an extremely fast, compact, powerful, embeddedable, transactional key-value storage engine with
44
* open-source code. MDBX has a specific set of properties and capabilities, focused on creating unique lightweight

mdbx_copy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00).
1+
/* This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00).
22
*
33
* libmdbx (aka MDBX) is an extremely fast, compact, powerful, embeddedable, transactional key-value storage engine with
44
* open-source code. MDBX has a specific set of properties and capabilities, focused on creating unique lightweight

mdbx_defrag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is part of the libmdbx amalgamated source code (v0.14.1-521-gb2ff247e at 2026-03-30T18:07:04+03:00).
1+
/* This file is part of the libmdbx amalgamated source code (v0.14.1-524-gba1be46d at 2026-03-31T02:48:49+03:00).
22
*
33
* libmdbx (aka MDBX) is an extremely fast, compact, powerful, embeddedable, transactional key-value storage engine with
44
* open-source code. MDBX has a specific set of properties and capabilities, focused on creating unique lightweight

0 commit comments

Comments
 (0)