mdbx: conform to and use -Wpedantic.

Change-Id: I3056af7ae53c5a7c3ecbfe828ab1d5ee94c2bc26
This commit is contained in:
Leonid Yuriev 2019-10-26 00:02:28 +03:00
parent c694325ab7
commit 84bff89eb1
9 changed files with 136 additions and 140 deletions

View File

@ -21,7 +21,7 @@ suffix ?=
CC ?= gcc CC ?= gcc
LD ?= ld LD ?= ld
MDBX_OPTIONS ?= -DNDEBUG=1 MDBX_OPTIONS ?= -DNDEBUG=1
CFLAGS ?= -Os -g3 -Wall -Werror -Wextra -ffunction-sections -fPIC -fvisibility=hidden -std=gnu11 -pthread -Wno-tautological-compare CFLAGS ?= -Os -g3 -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -std=gnu11 -pthread -Wno-tautological-compare
# LY: '--no-as-needed,-lrt' for ability to built with modern glibc, but then run with the old # LY: '--no-as-needed,-lrt' for ability to built with modern glibc, but then run with the old
LDFLAGS ?= $(shell $(LD) --help 2>/dev/null | grep -q -- --gc-sections && echo '-Wl,--gc-sections,-z,relro,-O1')$(shell $(LD) --help 2>/dev/null | grep -q -- -dead_strip && echo '-Wl,-dead_strip') LDFLAGS ?= $(shell $(LD) --help 2>/dev/null | grep -q -- --gc-sections && echo '-Wl,--gc-sections,-z,relro,-O1')$(shell $(LD) --help 2>/dev/null | grep -q -- -dead_strip && echo '-Wl,-dead_strip')

View File

@ -776,7 +776,8 @@ static __inline int thread_key_create(mdbx_thread_key_t *key) {
#else #else
rc = pthread_key_create(key, nullptr); rc = pthread_key_create(key, nullptr);
#endif #endif
mdbx_trace("&key = %p, value 0x%x, rc %d", key, (unsigned)*key, rc); mdbx_trace("&key = %p, value 0x%x, rc %d", __Wpedantic_format_voidptr(key),
(unsigned)*key, rc);
return rc; return rc;
} }
@ -837,7 +838,7 @@ __cold void mdbx_rthc_global_init(void) {
mdbx_ensure(nullptr, mdbx_ensure(nullptr,
pthread_key_create(&rthc_key, mdbx_rthc_thread_dtor) == 0); pthread_key_create(&rthc_key, mdbx_rthc_thread_dtor) == 0);
mdbx_trace("pid %d, &mdbx_rthc_key = %p, value 0x%x", mdbx_getpid(), mdbx_trace("pid %d, &mdbx_rthc_key = %p, value 0x%x", mdbx_getpid(),
&rthc_key, (unsigned)rthc_key); __Wpedantic_format_voidptr(&rthc_key), (unsigned)rthc_key);
#endif #endif
/* checking time conversion, this also avoids racing on 32-bit architectures /* checking time conversion, this also avoids racing on 32-bit architectures
* during writing calculated 64-bit ratio(s) into memory. */ * during writing calculated 64-bit ratio(s) into memory. */
@ -881,12 +882,14 @@ __cold void mdbx_rthc_thread_dtor(void *ptr) {
mdbx_trace("== thread 0x%" PRIxPTR mdbx_trace("== thread 0x%" PRIxPTR
", rthc %p, [%i], %p ... %p (%+i), rtch-pid %i, " ", rthc %p, [%i], %p ... %p (%+i), rtch-pid %i, "
"current-pid %i", "current-pid %i",
(uintptr_t)mdbx_thread_self(), rthc, i, rthc_table[i].begin, (uintptr_t)mdbx_thread_self(), __Wpedantic_format_voidptr(rthc),
rthc_table[i].end, (int)(rthc - rthc_table[i].begin), i, __Wpedantic_format_voidptr(rthc_table[i].begin),
rthc->mr_pid, self_pid); __Wpedantic_format_voidptr(rthc_table[i].end),
(int)(rthc - rthc_table[i].begin), rthc->mr_pid, self_pid);
if (rthc->mr_pid == self_pid) { if (rthc->mr_pid == self_pid) {
mdbx_trace("==== thread 0x%" PRIxPTR ", rthc %p, cleanup", mdbx_trace("==== thread 0x%" PRIxPTR ", rthc %p, cleanup",
(uintptr_t)mdbx_thread_self(), rthc); (uintptr_t)mdbx_thread_self(),
__Wpedantic_format_voidptr(rthc));
rthc->mr_pid = 0; rthc->mr_pid = 0;
} }
} }
@ -921,18 +924,14 @@ __cold void mdbx_rthc_thread_dtor(void *ptr) {
} }
__cold void mdbx_rthc_global_dtor(void) { __cold void mdbx_rthc_global_dtor(void) {
mdbx_trace( mdbx_trace(">> pid %d", mdbx_getpid());
">> pid %d, &mdbx_rthc_global_dtor %p, &mdbx_rthc_thread_dtor = %p, "
"&mdbx_rthc_remove = %p",
mdbx_getpid(), &mdbx_rthc_global_dtor, &mdbx_rthc_thread_dtor,
&mdbx_rthc_remove);
rthc_lock(); rthc_lock();
#if !defined(_WIN32) && !defined(_WIN64) #if !defined(_WIN32) && !defined(_WIN64)
char *rthc = (char *)pthread_getspecific(rthc_key); char *rthc = (char *)pthread_getspecific(rthc_key);
mdbx_trace("== thread 0x%" PRIxPTR ", rthc %p, pid %d, self-status %d", mdbx_trace("== thread 0x%" PRIxPTR ", rthc %p, pid %d, self-status %d",
(uintptr_t)mdbx_thread_self(), rthc, mdbx_getpid(), (uintptr_t)mdbx_thread_self(), __Wpedantic_format_voidptr(rthc),
rthc ? *rthc : -1); mdbx_getpid(), rthc ? *rthc : -1);
if (rthc) { if (rthc) {
const char self_registration = *(char *)rthc; const char self_registration = *(char *)rthc;
*rthc = MDBX_THREAD_RTHC_ZERO; *rthc = MDBX_THREAD_RTHC_ZERO;
@ -970,11 +969,14 @@ __cold void mdbx_rthc_global_dtor(void) {
++rthc) { ++rthc) {
mdbx_trace("== [%i] = key %zu, %p ... %p, rthc %p (%+i), " mdbx_trace("== [%i] = key %zu, %p ... %p, rthc %p (%+i), "
"rthc-pid %i, current-pid %i", "rthc-pid %i, current-pid %i",
i, (size_t)key, rthc_table[i].begin, rthc_table[i].end, rthc, i, (size_t)key,
__Wpedantic_format_voidptr(rthc_table[i].begin),
__Wpedantic_format_voidptr(rthc_table[i].end),
__Wpedantic_format_voidptr(rthc),
(int)(rthc - rthc_table[i].begin), rthc->mr_pid, self_pid); (int)(rthc - rthc_table[i].begin), rthc->mr_pid, self_pid);
if (rthc->mr_pid == self_pid) { if (rthc->mr_pid == self_pid) {
rthc->mr_pid = 0; rthc->mr_pid = 0;
mdbx_trace("== cleanup %p", rthc); mdbx_trace("== cleanup %p", __Wpedantic_format_voidptr(rthc));
} }
} }
} }
@ -1026,8 +1028,9 @@ __cold int mdbx_rthc_alloc(mdbx_thread_key_t *key, MDBX_reader *begin,
rthc_table = new_table; rthc_table = new_table;
rthc_limit *= 2; rthc_limit *= 2;
} }
mdbx_trace("== [%i] = key %zu, %p ... %p", rthc_count, (size_t)new_key, begin, mdbx_trace("== [%i] = key %zu, %p ... %p", rthc_count, (size_t)new_key,
end); __Wpedantic_format_voidptr(begin),
__Wpedantic_format_voidptr(end));
rthc_table[rthc_count].key_valid = key ? true : false; rthc_table[rthc_count].key_valid = key ? true : false;
rthc_table[rthc_count].thr_tls_key = key ? new_key : 0; rthc_table[rthc_count].thr_tls_key = key ? new_key : 0;
rthc_table[rthc_count].begin = begin; rthc_table[rthc_count].begin = begin;
@ -1054,14 +1057,15 @@ __cold void mdbx_rthc_remove(const mdbx_thread_key_t key) {
for (unsigned i = 0; i < rthc_count; ++i) { for (unsigned i = 0; i < rthc_count; ++i) {
if (rthc_table[i].key_valid && key == rthc_table[i].thr_tls_key) { if (rthc_table[i].key_valid && key == rthc_table[i].thr_tls_key) {
const uint32_t self_pid = mdbx_getpid(); const uint32_t self_pid = mdbx_getpid();
mdbx_trace("== [%i], %p ...%p, current-pid %d", i, rthc_table[i].begin, mdbx_trace("== [%i], %p ...%p, current-pid %d", i,
rthc_table[i].end, self_pid); __Wpedantic_format_voidptr(rthc_table[i].begin),
__Wpedantic_format_voidptr(rthc_table[i].end), self_pid);
for (MDBX_reader *rthc = rthc_table[i].begin; rthc < rthc_table[i].end; for (MDBX_reader *rthc = rthc_table[i].begin; rthc < rthc_table[i].end;
++rthc) { ++rthc) {
if (rthc->mr_pid == self_pid) { if (rthc->mr_pid == self_pid) {
rthc->mr_pid = 0; rthc->mr_pid = 0;
mdbx_trace("== cleanup %p", rthc); mdbx_trace("== cleanup %p", __Wpedantic_format_voidptr(rthc));
} }
} }
if (--rthc_count > 0) if (--rthc_count > 0)
@ -1165,7 +1169,7 @@ __cold static int uniq_check(const mdbx_mmap_t *pending, MDBX_env **found) {
if (likely(mdbx_filesize(pending->fd, &length) == MDBX_SUCCESS && if (likely(mdbx_filesize(pending->fd, &length) == MDBX_SUCCESS &&
length == 0)) { length == 0)) {
/* LY: skip checking since LCK-file is empty, i.e. just created. */ /* LY: skip checking since LCK-file is empty, i.e. just created. */
mdbx_debug("uniq-probe: unique (new/empty lck)"); mdbx_debug("uniq-probe: %s", "unique (new/empty lck)");
return MDBX_RESULT_TRUE; return MDBX_RESULT_TRUE;
} }
} }
@ -1178,7 +1182,7 @@ __cold static int uniq_check(const mdbx_mmap_t *pending, MDBX_env **found) {
if (err == MDBX_RESULT_TRUE) { if (err == MDBX_RESULT_TRUE) {
err = uniq_poke(pending, &scan->me_lck_mmap, &salt); err = uniq_poke(pending, &scan->me_lck_mmap, &salt);
*found = scan; *found = scan;
mdbx_debug("uniq-probe: found %p", *found); mdbx_debug("uniq-probe: found %p", __Wpedantic_format_voidptr(*found));
return MDBX_RESULT_FALSE; return MDBX_RESULT_FALSE;
} }
if (unlikely(err != MDBX_SUCCESS)) { if (unlikely(err != MDBX_SUCCESS)) {
@ -1187,7 +1191,7 @@ __cold static int uniq_check(const mdbx_mmap_t *pending, MDBX_env **found) {
} }
} }
mdbx_debug("uniq-probe: unique"); mdbx_debug("uniq-probe: %s", "unique");
return MDBX_RESULT_TRUE; return MDBX_RESULT_TRUE;
} }
@ -2770,9 +2774,9 @@ static __hot int mdbx_page_loose(MDBX_txn *txn, MDBX_page *mp) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
if (unlikely(mp != dp)) { /* bad cursor? */ if (unlikely(mp != dp)) { /* bad cursor? */
mdbx_error("wrong page 0x%p #%" PRIaPGNO mdbx_error(
" in the dirtylist, expecting %p", "wrong page 0x%p #%" PRIaPGNO " in the dirtylist, expecting %p",
dp, pgno, mp); __Wpedantic_format_voidptr(dp), pgno, __Wpedantic_format_voidptr(mp));
txn->mt_flags |= MDBX_TXN_ERROR; txn->mt_flags |= MDBX_TXN_ERROR;
return MDBX_PROBLEM; return MDBX_PROBLEM;
} }
@ -2796,8 +2800,8 @@ static __hot int mdbx_page_loose(MDBX_txn *txn, MDBX_page *mp) {
/* Remove from dirty list */ /* Remove from dirty list */
MDBX_page *dp = mdbx_dpl_remove(txn->tw.dirtylist, pgno); MDBX_page *dp = mdbx_dpl_remove(txn->tw.dirtylist, pgno);
if (unlikely(dp != mp)) { if (unlikely(dp != mp)) {
mdbx_error("not found page 0x%p #%" PRIaPGNO " in the dirtylist", mp, mdbx_error("not found page 0x%p #%" PRIaPGNO " in the dirtylist",
pgno); __Wpedantic_format_voidptr(mp), pgno);
txn->mt_flags |= MDBX_TXN_ERROR; txn->mt_flags |= MDBX_TXN_ERROR;
return MDBX_PROBLEM; return MDBX_PROBLEM;
} }
@ -3746,7 +3750,7 @@ skip_cache:
unsigned i; unsigned i;
for (i = gc_len; i; i--) for (i = gc_len; i; i--)
mdbx_debug_extra_print(" %" PRIaPGNO, gc_pnl[i]); mdbx_debug_extra_print(" %" PRIaPGNO, gc_pnl[i]);
mdbx_debug_extra_print("\n"); mdbx_debug_extra_print("%s", "\n");
} }
/* Merge in descending sorted order */ /* Merge in descending sorted order */
@ -4080,7 +4084,8 @@ __hot static int mdbx_page_touch(MDBX_cursor *mc) {
if (unlikely(mp != dp)) { /* bad cursor? */ if (unlikely(mp != dp)) { /* bad cursor? */
mdbx_error("wrong page 0x%p #%" PRIaPGNO mdbx_error("wrong page 0x%p #%" PRIaPGNO
" in the dirtylist, expecting %p", " in the dirtylist, expecting %p",
dp, pgno, mp); __Wpedantic_format_voidptr(dp), pgno,
__Wpedantic_format_voidptr(mp));
mc->mc_flags &= ~(C_INITIALIZED | C_EOF); mc->mc_flags &= ~(C_INITIALIZED | C_EOF);
rc = MDBX_PROBLEM; rc = MDBX_PROBLEM;
goto fail; goto fail;
@ -4560,7 +4565,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
if (unlikely(txn->mt_txnid == 0 || if (unlikely(txn->mt_txnid == 0 ||
txn->mt_txnid >= SAFE64_INVALID_THRESHOLD)) { txn->mt_txnid >= SAFE64_INVALID_THRESHOLD)) {
mdbx_error("environment corrupted by died writer, must shutdown!"); mdbx_error("%s", "environment corrupted by died writer, must shutdown!");
rc = MDBX_WANNA_RECOVERY; rc = MDBX_WANNA_RECOVERY;
goto bailout; goto bailout;
} }
@ -4593,7 +4598,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
const txnid_t snap = mdbx_meta_txnid_stable(env, meta); const txnid_t snap = mdbx_meta_txnid_stable(env, meta);
txn->mt_txnid = safe64_txnid_next(snap); txn->mt_txnid = safe64_txnid_next(snap);
if (unlikely(txn->mt_txnid >= SAFE64_INVALID_THRESHOLD)) { if (unlikely(txn->mt_txnid >= SAFE64_INVALID_THRESHOLD)) {
mdbx_debug("txnid overflow!"); mdbx_debug("%s", "txnid overflow!");
rc = MDBX_TXN_FULL; rc = MDBX_TXN_FULL;
goto bailout; goto bailout;
} }
@ -4632,7 +4637,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
txn->mt_dbflags[FREE_DBI] = DB_VALID; txn->mt_dbflags[FREE_DBI] = DB_VALID;
if (unlikely(env->me_flags & MDBX_FATAL_ERROR)) { if (unlikely(env->me_flags & MDBX_FATAL_ERROR)) {
mdbx_warning("environment had fatal error, must shutdown!"); mdbx_warning("%s", "environment had fatal error, must shutdown!");
rc = MDBX_PANIC; rc = MDBX_PANIC;
} else { } else {
const size_t size = pgno2bytes(env, txn->mt_end_pgno); const size_t size = pgno2bytes(env, txn->mt_end_pgno);
@ -5433,7 +5438,7 @@ static int mdbx_update_gc(MDBX_txn *txn) {
txn->mt_cursors[FREE_DBI] = &mc; txn->mt_cursors[FREE_DBI] = &mc;
retry: retry:
mdbx_trace(" >> restart"); mdbx_trace("%s", " >> restart");
mdbx_tassert( mdbx_tassert(
txn, mdbx_pnl_check4assert(txn->tw.reclaimed_pglist, txn->mt_next_pgno)); txn, mdbx_pnl_check4assert(txn->tw.reclaimed_pglist, txn->mt_next_pgno));
mdbx_tassert(txn, mdbx_dirtylist_check(txn)); mdbx_tassert(txn, mdbx_dirtylist_check(txn));
@ -5451,7 +5456,7 @@ retry:
while (true) { while (true) {
/* Come back here after each Put() in case retired-list changed */ /* Come back here after each Put() in case retired-list changed */
MDBX_val key, data; MDBX_val key, data;
mdbx_trace(" >> continue"); mdbx_trace("%s", " >> continue");
mdbx_tassert(txn, mdbx_pnl_check4assert(txn->tw.reclaimed_pglist, mdbx_tassert(txn, mdbx_pnl_check4assert(txn->tw.reclaimed_pglist,
txn->mt_next_pgno)); txn->mt_next_pgno));
@ -5650,7 +5655,7 @@ retry:
txn->mt_txnid, txn->mt_dbs[FREE_DBI].md_root, i); txn->mt_txnid, txn->mt_dbs[FREE_DBI].md_root, i);
for (; i; i--) for (; i; i--)
mdbx_debug_extra_print(" %" PRIaPGNO, txn->tw.retired_pages[i]); mdbx_debug_extra_print(" %" PRIaPGNO, txn->tw.retired_pages[i]);
mdbx_debug_extra_print("\n"); mdbx_debug_extra_print("%s", "\n");
} }
continue; continue;
} }
@ -5660,7 +5665,7 @@ retry:
txn->mt_next_pgno)); txn->mt_next_pgno));
mdbx_tassert(txn, txn->tw.loose_count == 0); mdbx_tassert(txn, txn->tw.loose_count == 0);
mdbx_trace(" >> reserving"); mdbx_trace("%s", " >> reserving");
if (mdbx_audit_enabled()) { if (mdbx_audit_enabled()) {
rc = mdbx_audit_ex(txn, retired_stored, false); rc = mdbx_audit_ex(txn, retired_stored, false);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
@ -5768,7 +5773,7 @@ retry:
if (gc_rid >= gc_first) if (gc_rid >= gc_first)
gc_rid = gc_first - 1; gc_rid = gc_first - 1;
if (unlikely(gc_rid == 0)) { if (unlikely(gc_rid == 0)) {
mdbx_error("** no GC tail-space to store"); mdbx_error("%s", "** no GC tail-space to store");
rc = MDBX_PROBLEM; rc = MDBX_PROBLEM;
goto bailout; goto bailout;
} }
@ -5842,7 +5847,7 @@ retry:
mdbx_tassert(txn, reservation_gc_id < *env->me_oldest); mdbx_tassert(txn, reservation_gc_id < *env->me_oldest);
if (unlikely(reservation_gc_id < 1 || if (unlikely(reservation_gc_id < 1 ||
reservation_gc_id >= *env->me_oldest)) { reservation_gc_id >= *env->me_oldest)) {
mdbx_error("** internal error (reservation_gc_id)"); mdbx_error("%s", "** internal error (reservation_gc_id)");
rc = MDBX_PROBLEM; rc = MDBX_PROBLEM;
goto bailout; goto bailout;
} }
@ -5879,7 +5884,7 @@ retry:
cleaned_gc_slot == cleaned_gc_slot ==
(txn->tw.lifo_reclaimed ? MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) : 0)); (txn->tw.lifo_reclaimed ? MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) : 0));
mdbx_trace(" >> filling"); mdbx_trace("%s", " >> filling");
/* Fill in the reserved records */ /* Fill in the reserved records */
filled_gc_slot = filled_gc_slot =
txn->tw.lifo_reclaimed txn->tw.lifo_reclaimed
@ -5976,7 +5981,7 @@ retry:
if (unlikely(txn->tw.lifo_reclaimed if (unlikely(txn->tw.lifo_reclaimed
? cleaned_gc_slot < MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) ? cleaned_gc_slot < MDBX_PNL_SIZE(txn->tw.lifo_reclaimed)
: cleaned_gc_id < txn->tw.last_reclaimed)) { : cleaned_gc_id < txn->tw.last_reclaimed)) {
mdbx_notice("** restart: reclaimed-slots changed"); mdbx_notice("%s", "** restart: reclaimed-slots changed");
goto retry; goto retry;
} }
@ -6216,7 +6221,7 @@ int mdbx_txn_commit(MDBX_txn *txn) {
} }
if (unlikely(txn != env->me_txn)) { if (unlikely(txn != env->me_txn)) {
mdbx_debug("attempt to commit unknown transaction"); mdbx_debug("%s", "attempt to commit unknown transaction");
rc = MDBX_EINVAL; rc = MDBX_EINVAL;
goto fail; goto fail;
} }
@ -6814,7 +6819,7 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *dest,
} }
if (META_IS_WEAK(dest)) { if (META_IS_WEAK(dest)) {
mdbx_error("no usable meta-pages, database is corrupted"); mdbx_error("%s", "no usable meta-pages, database is corrupted");
return rc; return rc;
} }
@ -7025,7 +7030,7 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
target = head; target = head;
else { else {
mdbx_ensure(env, mdbx_meta_eq(env, head, pending)); mdbx_ensure(env, mdbx_meta_eq(env, head, pending));
mdbx_debug("skip update meta"); mdbx_debug("%s", "skip update meta");
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
} else if (head == meta0) } else if (head == meta0)
@ -7118,7 +7123,7 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
(uint8_t *)target - env->me_map); (uint8_t *)target - env->me_map);
if (unlikely(rc != MDBX_SUCCESS)) { if (unlikely(rc != MDBX_SUCCESS)) {
undo: undo:
mdbx_debug("write failed, disk error?"); mdbx_debug("%s", "write failed, disk error?");
/* On a failure, the pagecache still contains the new data. /* On a failure, the pagecache still contains the new data.
* Try write some old data back, to prevent it from being used. */ * Try write some old data back, to prevent it from being used. */
mdbx_pwrite(env->me_fd, (void *)target, sizeof(MDBX_meta), mdbx_pwrite(env->me_fd, (void *)target, sizeof(MDBX_meta),
@ -7742,7 +7747,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
(env->me_flags & MDBX_RDONLY) != 0) (env->me_flags & MDBX_RDONLY) != 0)
return err; return err;
mdbx_debug("create new database"); mdbx_debug("%s", "create new database");
rc = /* new database */ MDBX_RESULT_TRUE; rc = /* new database */ MDBX_RESULT_TRUE;
if (!env->me_dbgeo.now) { if (!env->me_dbgeo.now) {
@ -7793,7 +7798,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
meta.mm_geo.grow * (uint64_t)meta.mm_psize, meta.mm_geo.grow * (uint64_t)meta.mm_psize,
meta.mm_geo.shrink * (uint64_t)meta.mm_psize, meta.mm_psize); meta.mm_geo.shrink * (uint64_t)meta.mm_psize, meta.mm_psize);
if (unlikely(err != MDBX_SUCCESS)) { if (unlikely(err != MDBX_SUCCESS)) {
mdbx_error("could not use present dbsize-params from db"); mdbx_error("%s", "could not use present dbsize-params from db");
return MDBX_INCOMPATIBLE; return MDBX_INCOMPATIBLE;
} }
} else if (env->me_dbgeo.now) { } else if (env->me_dbgeo.now) {
@ -7825,7 +7830,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
env->me_dbgeo.upper, env->me_dbgeo.grow, env->me_dbgeo.upper, env->me_dbgeo.grow,
env->me_dbgeo.shrink, meta.mm_psize); env->me_dbgeo.shrink, meta.mm_psize);
if (unlikely(err != MDBX_SUCCESS)) { if (unlikely(err != MDBX_SUCCESS)) {
mdbx_error("could not apply preconfigured dbsize-params to db"); mdbx_error("%s", "could not apply preconfigured dbsize-params to db");
return MDBX_INCOMPATIBLE; return MDBX_INCOMPATIBLE;
} }
@ -7882,10 +7887,10 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
if (env->me_flags & MDBX_RDONLY) { if (env->me_flags & MDBX_RDONLY) {
if (filesize_before_mmap % env->me_os_psize) { if (filesize_before_mmap % env->me_os_psize) {
mdbx_error("filesize should be rounded-up to system page"); mdbx_error("%s", "filesize should be rounded-up to system page");
return MDBX_WANNA_RECOVERY; return MDBX_WANNA_RECOVERY;
} }
mdbx_warning("ignore filesize mismatch in readonly-mode"); mdbx_warning("%s", "ignore filesize mismatch in readonly-mode");
} else { } else {
mdbx_verbose("resize datafile to %" PRIuSIZE " bytes, %" PRIaPGNO mdbx_verbose("resize datafile to %" PRIuSIZE " bytes, %" PRIaPGNO
" pages", " pages",
@ -7992,13 +7997,13 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
if (!env->me_lck) { if (!env->me_lck) {
/* LY: without-lck (read-only) mode, so it is imposible that other /* LY: without-lck (read-only) mode, so it is imposible that other
* process made weak checkpoint. */ * process made weak checkpoint. */
mdbx_error("without-lck, unable recovery/rollback"); mdbx_error("%s", "without-lck, unable recovery/rollback");
return MDBX_WANNA_RECOVERY; return MDBX_WANNA_RECOVERY;
} }
/* LY: assume just have a collision with other running process, /* LY: assume just have a collision with other running process,
* or someone make a weak checkpoint */ * or someone make a weak checkpoint */
mdbx_verbose("assume collision or online weak checkpoint"); mdbx_verbose("%s", "assume collision or online weak checkpoint");
break; break;
} }
@ -8225,7 +8230,7 @@ static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname,
env->me_lck->mti_os_and_format = MDBX_LOCK_FORMAT; env->me_lck->mti_os_and_format = MDBX_LOCK_FORMAT;
} else { } else {
if (env->me_lck->mti_magic_and_version != MDBX_LOCK_MAGIC) { if (env->me_lck->mti_magic_and_version != MDBX_LOCK_MAGIC) {
mdbx_error("lock region has invalid magic/version"); mdbx_error("%s", "lock region has invalid magic/version");
err = ((env->me_lck->mti_magic_and_version >> 8) != MDBX_MAGIC) err = ((env->me_lck->mti_magic_and_version >> 8) != MDBX_MAGIC)
? MDBX_INVALID ? MDBX_INVALID
: MDBX_VERSION_MISMATCH; : MDBX_VERSION_MISMATCH;
@ -8517,7 +8522,7 @@ int __cold mdbx_env_open(MDBX_env *env, const char *path, unsigned flags,
/* TODO: yield/relax cpu */ /* TODO: yield/relax cpu */
} }
if ((env->me_lck->mti_envmode ^ env->me_flags) & mode_flags) { if ((env->me_lck->mti_envmode ^ env->me_flags) & mode_flags) {
mdbx_error("current mode/flags incompatible with requested"); mdbx_error("%s", "current mode/flags incompatible with requested");
rc = MDBX_INCOMPATIBLE; rc = MDBX_INCOMPATIBLE;
goto bailout; goto bailout;
} }
@ -8736,7 +8741,7 @@ static int __hot mdbx_cmp_int_align4(const MDBX_val *a, const MDBX_val *b) {
return CMP2INT(unaligned_peek_u64(4, a->iov_base), return CMP2INT(unaligned_peek_u64(4, a->iov_base),
unaligned_peek_u64(4, b->iov_base)); unaligned_peek_u64(4, b->iov_base));
default: default:
mdbx_assert_fail(NULL, "invalid size for INTEGERKEY/INTEGERDUP", mdbx_func_, mdbx_assert_fail(NULL, "invalid size for INTEGERKEY/INTEGERDUP", __func__,
__LINE__); __LINE__);
return 0; return 0;
} }
@ -8753,7 +8758,7 @@ static int __hot mdbx_cmp_int_align2(const MDBX_val *a, const MDBX_val *b) {
return CMP2INT(unaligned_peek_u64(2, a->iov_base), return CMP2INT(unaligned_peek_u64(2, a->iov_base),
unaligned_peek_u64(2, b->iov_base)); unaligned_peek_u64(2, b->iov_base));
default: default:
mdbx_assert_fail(NULL, "invalid size for INTEGERKEY/INTEGERDUP", mdbx_func_, mdbx_assert_fail(NULL, "invalid size for INTEGERKEY/INTEGERDUP", __func__,
__LINE__); __LINE__);
return 0; return 0;
} }
@ -8772,7 +8777,7 @@ static int __hot mdbx_cmp_int_unaligned(const MDBX_val *a, const MDBX_val *b) {
return CMP2INT(unaligned_peek_u64(1, a->iov_base), return CMP2INT(unaligned_peek_u64(1, a->iov_base),
unaligned_peek_u64(1, b->iov_base)); unaligned_peek_u64(1, b->iov_base));
default: default:
mdbx_assert_fail(NULL, "invalid size for INTEGERKEY/INTEGERDUP", mdbx_func_, mdbx_assert_fail(NULL, "invalid size for INTEGERKEY/INTEGERDUP", __func__,
__LINE__); __LINE__);
return 0; return 0;
} }
@ -9137,7 +9142,7 @@ __hot static int mdbx_page_search(MDBX_cursor *mc, MDBX_val *key, int flags) {
/* Make sure the txn is still viable, then find the root from /* Make sure the txn is still viable, then find the root from
* the txn's db table and set it as the root of the cursor's stack. */ * the txn's db table and set it as the root of the cursor's stack. */
if (unlikely(mc->mc_txn->mt_flags & MDBX_TXN_BLOCKED)) { if (unlikely(mc->mc_txn->mt_flags & MDBX_TXN_BLOCKED)) {
mdbx_debug("transaction has failed, must abort"); mdbx_debug("%s", "transaction has failed, must abort");
return MDBX_BAD_TXN; return MDBX_BAD_TXN;
} }
@ -9176,7 +9181,7 @@ __hot static int mdbx_page_search(MDBX_cursor *mc, MDBX_val *key, int flags) {
root = mc->mc_db->md_root; root = mc->mc_db->md_root;
if (unlikely(root == P_INVALID)) { /* Tree is empty. */ if (unlikely(root == P_INVALID)) { /* Tree is empty. */
mdbx_debug("tree is empty"); mdbx_debug("%s", "tree is empty");
return MDBX_NOTFOUND; return MDBX_NOTFOUND;
} }
@ -9442,7 +9447,7 @@ static int mdbx_cursor_next(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
} }
if (mc->mc_ki[mc->mc_top] + 1u >= page_numkeys(mp)) { if (mc->mc_ki[mc->mc_top] + 1u >= page_numkeys(mp)) {
mdbx_debug("=====> move to next sibling page"); mdbx_debug("%s", "=====> move to next sibling page");
if (unlikely((rc = mdbx_cursor_sibling(mc, 1)) != MDBX_SUCCESS)) { if (unlikely((rc = mdbx_cursor_sibling(mc, 1)) != MDBX_SUCCESS)) {
mc->mc_flags |= C_EOF; mc->mc_flags |= C_EOF;
return rc; return rc;
@ -9535,7 +9540,7 @@ static int mdbx_cursor_prev(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
mc->mc_flags &= ~(C_EOF | C_DEL); mc->mc_flags &= ~(C_EOF | C_DEL);
if (mc->mc_ki[mc->mc_top] == 0) { if (mc->mc_ki[mc->mc_top] == 0) {
mdbx_debug("=====> move to prev sibling page"); mdbx_debug("%s", "=====> move to prev sibling page");
if ((rc = mdbx_cursor_sibling(mc, 0)) != MDBX_SUCCESS) { if ((rc = mdbx_cursor_sibling(mc, 0)) != MDBX_SUCCESS) {
return rc; return rc;
} }
@ -9707,7 +9712,7 @@ set2:
} }
if (node == NULL) { if (node == NULL) {
mdbx_debug("===> inexact leaf not found, goto sibling"); mdbx_debug("%s", "===> inexact leaf not found, goto sibling");
if (unlikely((rc = mdbx_cursor_sibling(mc, 1)) != MDBX_SUCCESS)) { if (unlikely((rc = mdbx_cursor_sibling(mc, 1)) != MDBX_SUCCESS)) {
mc->mc_flags |= C_EOF; mc->mc_flags |= C_EOF;
return rc; /* no entries matched */ return rc; /* no entries matched */
@ -10234,7 +10239,7 @@ int mdbx_cursor_put(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
if (rc == MDBX_NO_ROOT) { if (rc == MDBX_NO_ROOT) {
MDBX_page *np; MDBX_page *np;
/* new database, write a root leaf page */ /* new database, write a root leaf page */
mdbx_debug("allocating new root leaf page"); mdbx_debug("%s", "allocating new root leaf page");
if (unlikely(rc2 = mdbx_page_new(mc, P_LEAF, 1, &np))) { if (unlikely(rc2 = mdbx_page_new(mc, P_LEAF, 1, &np))) {
return rc2; return rc2;
} }
@ -12169,13 +12174,13 @@ static int mdbx_rebalance(MDBX_cursor *mc) {
const unsigned nkeys = page_numkeys(mp); const unsigned nkeys = page_numkeys(mp);
mdbx_cassert(mc, (mc->mc_db->md_entries == 0) == (nkeys == 0)); mdbx_cassert(mc, (mc->mc_db->md_entries == 0) == (nkeys == 0));
if (IS_SUBP(mp)) { if (IS_SUBP(mp)) {
mdbx_debug("Can't rebalance a subpage, ignoring"); mdbx_debug("%s", "Can't rebalance a subpage, ignoring");
mdbx_cassert(mc, pagetype & P_LEAF); mdbx_cassert(mc, pagetype & P_LEAF);
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
if (nkeys == 0) { if (nkeys == 0) {
mdbx_cassert(mc, IS_LEAF(mp)); mdbx_cassert(mc, IS_LEAF(mp));
mdbx_debug("tree is completely empty"); mdbx_debug("%s", "tree is completely empty");
mc->mc_db->md_root = P_INVALID; mc->mc_db->md_root = P_INVALID;
mc->mc_db->md_depth = 0; mc->mc_db->md_depth = 0;
mdbx_cassert(mc, mc->mc_db->md_branch_pages == 0 && mdbx_cassert(mc, mc->mc_db->md_branch_pages == 0 &&
@ -12203,7 +12208,7 @@ static int mdbx_rebalance(MDBX_cursor *mc) {
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
return rc; return rc;
} else if (IS_BRANCH(mp) && nkeys == 1) { } else if (IS_BRANCH(mp) && nkeys == 1) {
mdbx_debug("collapsing root page!"); mdbx_debug("%s", "collapsing root page!");
mc->mc_db->md_root = node_pgno(page_node(mp, 0)); mc->mc_db->md_root = node_pgno(page_node(mp, 0));
rc = mdbx_page_get(mc, mc->mc_db->md_root, &mc->mc_pg[0], NULL); rc = mdbx_page_get(mc, mc->mc_db->md_root, &mc->mc_pg[0], NULL);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
@ -12267,7 +12272,7 @@ static int mdbx_rebalance(MDBX_cursor *mc) {
bool fromleft; bool fromleft;
if (mc->mc_ki[pre_top] == 0) { if (mc->mc_ki[pre_top] == 0) {
/* We're the leftmost leaf in our parent. */ /* We're the leftmost leaf in our parent. */
mdbx_debug("reading right neighbor"); mdbx_debug("%s", "reading right neighbor");
mn.mc_ki[pre_top]++; mn.mc_ki[pre_top]++;
node = page_node(mc->mc_pg[pre_top], mn.mc_ki[pre_top]); node = page_node(mc->mc_pg[pre_top], mn.mc_ki[pre_top]);
rc = mdbx_page_get(mc, node_pgno(node), &mn.mc_pg[mn.mc_top], NULL); rc = mdbx_page_get(mc, node_pgno(node), &mn.mc_pg[mn.mc_top], NULL);
@ -12280,7 +12285,7 @@ static int mdbx_rebalance(MDBX_cursor *mc) {
fromleft = false; fromleft = false;
} else { } else {
/* There is at least one neighbor to the left. */ /* There is at least one neighbor to the left. */
mdbx_debug("reading left neighbor"); mdbx_debug("%s", "reading left neighbor");
mn.mc_ki[pre_top]--; mn.mc_ki[pre_top]--;
node = page_node(mc->mc_pg[pre_top], mn.mc_ki[pre_top]); node = page_node(mc->mc_pg[pre_top], mn.mc_ki[pre_top]);
rc = mdbx_page_get(mc, node_pgno(node), &mn.mc_pg[mn.mc_top], NULL); rc = mdbx_page_get(mc, node_pgno(node), &mn.mc_pg[mn.mc_top], NULL);
@ -14936,7 +14941,7 @@ int __cold mdbx_setup_debug(int loglevel, int flags, MDBX_debug_func *logger) {
} }
static txnid_t __cold mdbx_oomkick(MDBX_env *env, const txnid_t laggard) { static txnid_t __cold mdbx_oomkick(MDBX_env *env, const txnid_t laggard) {
mdbx_debug("DB size maxed out"); mdbx_debug("%s", "DB size maxed out");
int retry; int retry;
for (retry = 0; retry < INT_MAX; ++retry) { for (retry = 0; retry < INT_MAX; ++retry) {

View File

@ -152,22 +152,7 @@
#endif /* __deprecated */ #endif /* __deprecated */
#if !defined(__noop) && !defined(_MSC_VER) #if !defined(__noop) && !defined(_MSC_VER)
# ifdef __cplusplus
static __maybe_unused inline void __noop_consume_args() {}
template <typename First, typename... Rest>
static inline void
__noop_consume_args(const First &first, const Rest &... rest) {
(void) first; __noop_consume_args(rest...);
}
# define __noop(...) __noop_consume_args(__VA_ARGS__)
# elif defined(__GNUC__) && (!defined(__STRICT_ANSI__) || !__STRICT_ANSI__)
static __maybe_unused __inline void __noop_consume_args(void* anchor, ...) {
(void) anchor;
}
# define __noop(...) __noop_consume_args(0, ##__VA_ARGS__)
# else
# define __noop(...) do {} while(0) # define __noop(...) do {} while(0)
# endif
#endif /* __noop */ #endif /* __noop */
#ifndef __fallthrough #ifndef __fallthrough
@ -345,21 +330,28 @@ typedef __complex__ float __cfloat128 __attribute__ ((__mode__ (__TC__)));
typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__))); typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
#endif /* Workaround for Coverity Scan */ #endif /* Workaround for Coverity Scan */
/* Wrapper around __func__, which is a C99 feature */ #ifndef __printf_args
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L # if defined(__GNUC__) || __has_attribute(__format__)
# define mdbx_func_ __func__ # define __printf_args(format_index, first_arg) \
#elif (defined(__GNUC__) && __GNUC__ >= 2) || defined(__clang__) || defined(_MSC_VER) __attribute__((__format__(printf, format_index, first_arg)))
# define mdbx_func_ __func__ # else
#else # define __printf_args(format_index, first_arg)
# define mdbx_func_ "<mdbx_unknown>" # endif
#endif #endif /* __printf_args */
#if defined(__GNUC__) || __has_attribute(__format__) #ifndef __anonymous_struct_extension__
#define __printf_args(format_index, first_arg) \ # if defined(__GNUC__)
__attribute__((__format__(printf, format_index, first_arg))) # define __anonymous_struct_extension__ __extension__
#else # else
#define __printf_args(format_index, first_arg) # define __anonymous_struct_extension__
#endif # endif
#endif /* __anonymous_struct_extension__ */
#ifndef __Wpedantic_format_voidptr
static __inline const void* __pure_function
__Wpedantic_format_voidptr(const void* ptr) {return ptr;}
# define __Wpedantic_format_voidptr(ARG) __Wpedantic_format_voidptr(ARG)
#endif /* __Wpedantic_format_voidptr */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View File

@ -1090,65 +1090,65 @@ MDBX_INTERNAL_FUNC void mdbx_assert_fail(const MDBX_env *env, const char *msg,
#define mdbx_debug_extra(fmt, ...) \ #define mdbx_debug_extra(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_EXTRA)) \ if (mdbx_log_enabled(MDBX_LOG_EXTRA)) \
mdbx_debug_log(MDBX_LOG_EXTRA, __func__, __LINE__, fmt, ##__VA_ARGS__); \ mdbx_debug_log(MDBX_LOG_EXTRA, __func__, __LINE__, fmt, __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_debug_extra_print(fmt, ...) \ #define mdbx_debug_extra_print(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_EXTRA)) \ if (mdbx_log_enabled(MDBX_LOG_EXTRA)) \
mdbx_debug_log(MDBX_LOG_EXTRA, NULL, 0, fmt, ##__VA_ARGS__); \ mdbx_debug_log(MDBX_LOG_EXTRA, NULL, 0, fmt, __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_trace(fmt, ...) \ #define mdbx_trace(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_TRACE)) \ if (mdbx_log_enabled(MDBX_LOG_TRACE)) \
mdbx_debug_log(MDBX_LOG_TRACE, __func__, __LINE__, fmt "\n", \ mdbx_debug_log(MDBX_LOG_TRACE, __func__, __LINE__, fmt "\n", \
##__VA_ARGS__); \ __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_debug(fmt, ...) \ #define mdbx_debug(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_DEBUG)) \ if (mdbx_log_enabled(MDBX_LOG_DEBUG)) \
mdbx_debug_log(MDBX_LOG_DEBUG, __func__, __LINE__, fmt "\n", \ mdbx_debug_log(MDBX_LOG_DEBUG, __func__, __LINE__, fmt "\n", \
##__VA_ARGS__); \ __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_debug_print(fmt, ...) \ #define mdbx_debug_print(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_DEBUG)) \ if (mdbx_log_enabled(MDBX_LOG_DEBUG)) \
mdbx_debug_log(MDBX_LOG_DEBUG, NULL, 0, fmt, ##__VA_ARGS__); \ mdbx_debug_log(MDBX_LOG_DEBUG, NULL, 0, fmt, __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_verbose(fmt, ...) \ #define mdbx_verbose(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_VERBOSE)) \ if (mdbx_log_enabled(MDBX_LOG_VERBOSE)) \
mdbx_debug_log(MDBX_LOG_VERBOSE, __func__, __LINE__, fmt "\n", \ mdbx_debug_log(MDBX_LOG_VERBOSE, __func__, __LINE__, fmt "\n", \
##__VA_ARGS__); \ __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_notice(fmt, ...) \ #define mdbx_notice(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_NOTICE)) \ if (mdbx_log_enabled(MDBX_LOG_NOTICE)) \
mdbx_debug_log(MDBX_LOG_NOTICE, __func__, __LINE__, fmt "\n", \ mdbx_debug_log(MDBX_LOG_NOTICE, __func__, __LINE__, fmt "\n", \
##__VA_ARGS__); \ __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_warning(fmt, ...) \ #define mdbx_warning(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_WARN)) \ if (mdbx_log_enabled(MDBX_LOG_WARN)) \
mdbx_debug_log(MDBX_LOG_WARN, __func__, __LINE__, fmt "\n", \ mdbx_debug_log(MDBX_LOG_WARN, __func__, __LINE__, fmt "\n", \
##__VA_ARGS__); \ __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_error(fmt, ...) \ #define mdbx_error(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_ERROR)) \ if (mdbx_log_enabled(MDBX_LOG_ERROR)) \
mdbx_debug_log(MDBX_LOG_ERROR, __func__, __LINE__, fmt "\n", \ mdbx_debug_log(MDBX_LOG_ERROR, __func__, __LINE__, fmt "\n", \
##__VA_ARGS__); \ __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_fatal(fmt, ...) \ #define mdbx_fatal(fmt, ...) \
mdbx_debug_log(MDBX_LOG_FATAL, __func__, __LINE__, fmt "\n", ##__VA_ARGS__); mdbx_debug_log(MDBX_LOG_FATAL, __func__, __LINE__, fmt "\n", __VA_ARGS__);
#define mdbx_ensure_msg(env, expr, msg) \ #define mdbx_ensure_msg(env, expr, msg) \
do { \ do { \

View File

@ -211,7 +211,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_seize(MDBX_env *env) {
lck_op(env->me_fd, op_setlk, lck_op(env->me_fd, op_setlk,
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX); (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, "without-lck", rc); mdbx_error("%s(%s) failed: errcode %u", __func__, "without-lck", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); mdbx_assert(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
@ -231,7 +231,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_seize(MDBX_env *env) {
/* the cause may be a collision with POSIX's file-lock recovery. */ /* the cause may be a collision with POSIX's file-lock recovery. */
if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK || if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK ||
rc == EDEADLK)) { rc == EDEADLK)) {
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, "dxb-exclusive", rc); mdbx_error("%s(%s) failed: errcode %u", __func__, "dxb-exclusive", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); mdbx_assert(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
@ -239,8 +239,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_seize(MDBX_env *env) {
/* Fallback to lck-shared */ /* Fallback to lck-shared */
rc = lck_op(env->me_lfd, op_setlk, F_RDLCK, 0, 1); rc = lck_op(env->me_lfd, op_setlk, F_RDLCK, 0, 1);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, "fallback-shared", mdbx_error("%s(%s) failed: errcode %u", __func__, "fallback-shared", rc);
rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); mdbx_assert(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
@ -253,7 +252,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_seize(MDBX_env *env) {
* competing process doesn't call lck_downgrade(). */ * competing process doesn't call lck_downgrade(). */
rc = lck_op(env->me_lfd, op_setlkw, F_RDLCK, 0, 1); rc = lck_op(env->me_lfd, op_setlkw, F_RDLCK, 0, 1);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, "try-shared", rc); mdbx_error("%s(%s) failed: errcode %u", __func__, "try-shared", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); mdbx_assert(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
@ -263,7 +262,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_seize(MDBX_env *env) {
lck_op(env->me_fd, op_setlk, lck_op(env->me_fd, op_setlk,
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, env->me_pid, 1); (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, env->me_pid, 1);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, mdbx_error("%s(%s) failed: errcode %u", __func__,
"lock-against-without-lck", rc); "lock-against-without-lck", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); mdbx_assert(env, MDBX_IS_ERROR(rc));
return rc; return rc;
@ -280,7 +279,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_seize(MDBX_env *env) {
but shared locks are alive. */ but shared locks are alive. */
; ;
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, "try-exclusive", rc); mdbx_error("%s(%s) failed: errcode %u", __func__, "try-exclusive", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); mdbx_assert(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
@ -300,7 +299,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) {
if (rc == MDBX_SUCCESS) if (rc == MDBX_SUCCESS)
rc = lck_op(env->me_lfd, op_setlk, F_RDLCK, 0, 1); rc = lck_op(env->me_lfd, op_setlk, F_RDLCK, 0, 1);
if (unlikely(rc != 0)) { if (unlikely(rc != 0)) {
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, "lck", rc); mdbx_error("%s(%s) failed: errcode %u", __func__, "lck", rc);
assert(MDBX_IS_ERROR(rc)); assert(MDBX_IS_ERROR(rc));
} }
return rc; return rc;
@ -318,7 +317,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_destroy(MDBX_env *env,
lck_op(env->me_lfd, op_setlk, F_WRLCK, 0, OFF_T_MAX) == 0 && lck_op(env->me_lfd, op_setlk, F_WRLCK, 0, OFF_T_MAX) == 0 &&
lck_op(env->me_fd, op_setlk, lck_op(env->me_fd, op_setlk,
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX)) { (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX)) {
mdbx_verbose("%s: got exclusive, drown mutexes", mdbx_func_); mdbx_verbose("%s: got exclusive, drown mutexes", __func__);
rc = pthread_mutex_destroy(&env->me_lck->mti_rmutex); rc = pthread_mutex_destroy(&env->me_lck->mti_rmutex);
if (rc == 0) if (rc == 0)
rc = pthread_mutex_destroy(&env->me_lck->mti_wmutex); rc = pthread_mutex_destroy(&env->me_lck->mti_wmutex);
@ -472,22 +471,22 @@ static int mdbx_robust_unlock(MDBX_env *env, pthread_mutex_t *mutex) {
} }
MDBX_INTERNAL_FUNC int mdbx_rdt_lock(MDBX_env *env) { MDBX_INTERNAL_FUNC int mdbx_rdt_lock(MDBX_env *env) {
mdbx_trace(">>"); mdbx_trace("%s", ">>");
int rc = mdbx_robust_lock(env, &env->me_lck->mti_rmutex); int rc = mdbx_robust_lock(env, &env->me_lck->mti_rmutex);
mdbx_trace("<< rc %d", rc); mdbx_trace("<< rc %d", rc);
return rc; return rc;
} }
MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env) { MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env) {
mdbx_trace(">>"); mdbx_trace("%s", ">>");
int rc = mdbx_robust_unlock(env, &env->me_lck->mti_rmutex); int rc = mdbx_robust_unlock(env, &env->me_lck->mti_rmutex);
mdbx_trace("<< rc %d", rc); mdbx_trace("<< rc %d", rc);
if (unlikely(MDBX_IS_ERROR(rc))) if (unlikely(MDBX_IS_ERROR(rc)))
mdbx_panic("%s() failed: errcode %d\n", mdbx_func_, rc); mdbx_panic("%s() failed: errcode %d\n", __func__, rc);
} }
int mdbx_txn_lock(MDBX_env *env, bool dontwait) { int mdbx_txn_lock(MDBX_env *env, bool dontwait) {
mdbx_trace(">>"); mdbx_trace("%s", ">>");
int rc = dontwait ? mdbx_robust_trylock(env, env->me_wmutex) int rc = dontwait ? mdbx_robust_trylock(env, env->me_wmutex)
: mdbx_robust_lock(env, env->me_wmutex); : mdbx_robust_lock(env, env->me_wmutex);
mdbx_trace("<< rc %d", rc); mdbx_trace("<< rc %d", rc);
@ -495,11 +494,11 @@ int mdbx_txn_lock(MDBX_env *env, bool dontwait) {
} }
void mdbx_txn_unlock(MDBX_env *env) { void mdbx_txn_unlock(MDBX_env *env) {
mdbx_trace(">>"); mdbx_trace("%s", ">>");
int rc = mdbx_robust_unlock(env, env->me_wmutex); int rc = mdbx_robust_unlock(env, env->me_wmutex);
mdbx_trace("<< rc %d", rc); mdbx_trace("<< rc %d", rc);
if (unlikely(MDBX_IS_ERROR(rc))) if (unlikely(MDBX_IS_ERROR(rc)))
mdbx_panic("%s() failed: errcode %d\n", mdbx_func_, rc); mdbx_panic("%s() failed: errcode %d\n", __func__, rc);
} }
static int __cold mdbx_mutex_failed(MDBX_env *env, pthread_mutex_t *mutex, static int __cold mdbx_mutex_failed(MDBX_env *env, pthread_mutex_t *mutex,

View File

@ -166,7 +166,7 @@ void mdbx_txn_unlock(MDBX_env *env) {
(env->me_flags & MDBX_EXCLUSIVE) ? TRUE : funlock(env->me_fd, LCK_BODY); (env->me_flags & MDBX_EXCLUSIVE) ? TRUE : funlock(env->me_fd, LCK_BODY);
LeaveCriticalSection(&env->me_windowsbug_lock); LeaveCriticalSection(&env->me_windowsbug_lock);
if (!rc) if (!rc)
mdbx_panic("%s failed: errcode %u", mdbx_func_, GetLastError()); mdbx_panic("%s failed: errcode %u", __func__, GetLastError());
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -200,7 +200,7 @@ MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env) {
/* transite from S-E (locked) to S-? (used), e.g. unlock upper-part */ /* transite from S-E (locked) to S-? (used), e.g. unlock upper-part */
if ((env->me_flags & MDBX_EXCLUSIVE) == 0 && if ((env->me_flags & MDBX_EXCLUSIVE) == 0 &&
!funlock(env->me_lfd, LCK_UPPER)) !funlock(env->me_lfd, LCK_UPPER))
mdbx_panic("%s failed: errcode %u", mdbx_func_, GetLastError()); mdbx_panic("%s failed: errcode %u", __func__, GetLastError());
} }
mdbx_srwlock_ReleaseShared(&env->me_remap_guard); mdbx_srwlock_ReleaseShared(&env->me_remap_guard);
} }
@ -438,7 +438,7 @@ static int internal_seize_lck(HANDLE lfd) {
mdbx_jitter4testing(false); mdbx_jitter4testing(false);
if (!flock(lfd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_UPPER)) { if (!flock(lfd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_UPPER)) {
rc = GetLastError() /* 2) something went wrong, give up */; rc = GetLastError() /* 2) something went wrong, give up */;
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, mdbx_error("%s(%s) failed: errcode %u", __func__,
"?-?(free) >> ?-E(middle)", rc); "?-?(free) >> ?-E(middle)", rc);
return rc; return rc;
} }
@ -454,7 +454,7 @@ static int internal_seize_lck(HANDLE lfd) {
if (rc != ERROR_SHARING_VIOLATION && rc != ERROR_LOCK_VIOLATION) { if (rc != ERROR_SHARING_VIOLATION && rc != ERROR_LOCK_VIOLATION) {
/* 6) something went wrong, give up */ /* 6) something went wrong, give up */
if (!funlock(lfd, LCK_UPPER)) if (!funlock(lfd, LCK_UPPER))
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_, mdbx_panic("%s(%s) failed: errcode %u", __func__,
"?-E(middle) >> ?-?(free)", GetLastError()); "?-E(middle) >> ?-?(free)", GetLastError());
return rc; return rc;
} }
@ -466,13 +466,13 @@ static int internal_seize_lck(HANDLE lfd) {
mdbx_jitter4testing(false); mdbx_jitter4testing(false);
if (rc != MDBX_RESULT_FALSE) if (rc != MDBX_RESULT_FALSE)
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, mdbx_error("%s(%s) failed: errcode %u", __func__,
"?-E(middle) >> S-E(locked)", rc); "?-E(middle) >> S-E(locked)", rc);
/* 8) now on S-E (locked) or still on ?-E (middle), /* 8) now on S-E (locked) or still on ?-E (middle),
* transite to S-? (used) or ?-? (free) */ * transite to S-? (used) or ?-? (free) */
if (!funlock(lfd, LCK_UPPER)) if (!funlock(lfd, LCK_UPPER))
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_, mdbx_panic("%s(%s) failed: errcode %u", __func__,
"X-E(locked/middle) >> X-?(used/free)", GetLastError()); "X-E(locked/middle) >> X-?(used/free)", GetLastError());
/* 9) now on S-? (used, DONE) or ?-? (free, FAILURE) */ /* 9) now on S-? (used, DONE) or ?-? (free, FAILURE) */
@ -493,7 +493,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
mdbx_jitter4testing(false); mdbx_jitter4testing(false);
if (!flock(env->me_fd, LCK_SHARED | LCK_DONTWAIT, LCK_WHOLE)) { if (!flock(env->me_fd, LCK_SHARED | LCK_DONTWAIT, LCK_WHOLE)) {
rc = GetLastError(); rc = GetLastError();
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, "without-lck", rc); mdbx_error("%s(%s) failed: errcode %u", __func__, "without-lck", rc);
return rc; return rc;
} }
return MDBX_RESULT_FALSE; return MDBX_RESULT_FALSE;
@ -510,14 +510,14 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
* while opening db in valid (non-conflict) mode. */ * while opening db in valid (non-conflict) mode. */
if (!flock(env->me_fd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_BODY)) { if (!flock(env->me_fd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_BODY)) {
rc = GetLastError(); rc = GetLastError();
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, mdbx_error("%s(%s) failed: errcode %u", __func__,
"lock-against-without-lck", rc); "lock-against-without-lck", rc);
mdbx_jitter4testing(false); mdbx_jitter4testing(false);
lck_unlock(env); lck_unlock(env);
} else { } else {
mdbx_jitter4testing(false); mdbx_jitter4testing(false);
if (!funlock(env->me_fd, LCK_BODY)) if (!funlock(env->me_fd, LCK_BODY))
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_, mdbx_panic("%s(%s) failed: errcode %u", __func__,
"unlock-against-without-lck", GetLastError()); "unlock-against-without-lck", GetLastError());
} }
} }
@ -539,7 +539,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) {
if (env->me_flags & MDBX_EXCLUSIVE) { if (env->me_flags & MDBX_EXCLUSIVE) {
/* transite from E-E to E_? (exclusive-read) */ /* transite from E-E to E_? (exclusive-read) */
if (!funlock(env->me_lfd, LCK_UPPER)) if (!funlock(env->me_lfd, LCK_UPPER))
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_, mdbx_panic("%s(%s) failed: errcode %u", __func__,
"E-E(exclusive-write) >> E-?(exclusive-read)", GetLastError()); "E-E(exclusive-write) >> E-?(exclusive-read)", GetLastError());
return MDBX_SUCCESS /* 2) now at E-? (exclusive-read), done */; return MDBX_SUCCESS /* 2) now at E-? (exclusive-read), done */;
} }
@ -547,20 +547,20 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) {
/* 3) now at E-E (exclusive-write), transite to ?_E (middle) */ /* 3) now at E-E (exclusive-write), transite to ?_E (middle) */
if (!funlock(env->me_lfd, LCK_LOWER)) if (!funlock(env->me_lfd, LCK_LOWER))
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_, mdbx_panic("%s(%s) failed: errcode %u", __func__,
"E-E(exclusive-write) >> ?-E(middle)", GetLastError()); "E-E(exclusive-write) >> ?-E(middle)", GetLastError());
/* 4) now at ?-E (middle), transite to S-E (locked) */ /* 4) now at ?-E (middle), transite to S-E (locked) */
if (!flock(env->me_lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER)) { if (!flock(env->me_lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER)) {
int rc = GetLastError() /* 5) something went wrong, give up */; int rc = GetLastError() /* 5) something went wrong, give up */;
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, mdbx_error("%s(%s) failed: errcode %u", __func__,
"?-E(middle) >> S-E(locked)", rc); "?-E(middle) >> S-E(locked)", rc);
return rc; return rc;
} }
/* 6) got S-E (locked), continue transition to S-? (used) */ /* 6) got S-E (locked), continue transition to S-? (used) */
if (!funlock(env->me_lfd, LCK_UPPER)) if (!funlock(env->me_lfd, LCK_UPPER))
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_, mdbx_panic("%s(%s) failed: errcode %u", __func__,
"S-E(locked) >> S-?(used)", GetLastError()); "S-E(locked) >> S-?(used)", GetLastError());
return MDBX_SUCCESS /* 7) now at S-? (used), done */; return MDBX_SUCCESS /* 7) now at S-? (used), done */;

View File

@ -23,7 +23,7 @@ namespace chrono {
typedef union time { typedef union time {
uint64_t fixedpoint; uint64_t fixedpoint;
struct { __anonymous_struct_extension__ struct {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
uint32_t fractional; uint32_t fractional;
union { union {

View File

@ -90,7 +90,7 @@ void osal_setup(const std::vector<actor_config> &actors) {
if (rc) if (rc)
failure_perror("pthread_cond_init(shared)", rc); failure_perror("pthread_cond_init(shared)", rc);
log_trace("osal_setup: event(shared pthread_cond) %" PRIuPTR " -> %p", i, log_trace("osal_setup: event(shared pthread_cond) %" PRIuPTR " -> %p", i,
event); __Wpedantic_format_voidptr(event));
} }
shared->conds_size = actors.size() + 1; shared->conds_size = actors.size() + 1;

View File

@ -82,7 +82,7 @@ struct txn_deleter /* : public std::unary_function<void, MDBX_txn *> */ {
void operator()(MDBX_txn *txn) const { void operator()(MDBX_txn *txn) const {
int rc = mdbx_txn_abort(txn); int rc = mdbx_txn_abort(txn);
if (rc) if (rc)
log_trouble(mdbx_func_, "mdbx_txn_abort()", rc); log_trouble(__func__, "mdbx_txn_abort()", rc);
} }
}; };