mdbx++: changes after codereview-1 (part 2 of 2).

Change-Id: I8e1ca134bb8c5d447895f116247dfd12fa6871f0
This commit is contained in:
Leonid Yuriev
2020-09-14 16:40:46 +03:00
parent 04b0d258ff
commit cacc4aa829
15 changed files with 631 additions and 628 deletions

View File

@@ -40,7 +40,7 @@
/*------------------------------------------------------------------------------
* Internal inlines */
__nothrow_const_function static unsigned log2n(size_t value) {
MDBX_NOTHROW_CONST_FUNCTION static unsigned log2n(size_t value) {
assert(value > 0 && value < INT32_MAX && is_powerof2(value));
assert((value & -(int32_t)value) == value);
#if __GNUC_PREREQ(4, 1) || __has_builtin(__builtin_ctzl)
@@ -60,14 +60,14 @@ __nothrow_const_function static unsigned log2n(size_t value) {
/*------------------------------------------------------------------------------
* Unaligned access */
__nothrow_const_function static __maybe_unused __always_inline unsigned
MDBX_NOTHROW_CONST_FUNCTION static __maybe_unused __always_inline unsigned
field_alignment(unsigned alignment_baseline, size_t field_offset) {
unsigned merge = alignment_baseline | (unsigned)field_offset;
return merge & -(int)merge;
}
/* read-thunk for UB-sanitizer */
__nothrow_pure_function static __always_inline uint8_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline uint8_t
peek_u8(const uint8_t *const __restrict ptr) {
return *ptr;
}
@@ -78,7 +78,7 @@ static __always_inline void poke_u8(uint8_t *const __restrict ptr,
*ptr = v;
}
__nothrow_pure_function static __always_inline uint16_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline uint16_t
unaligned_peek_u16(const unsigned expected_alignment, const void *const ptr) {
assert((uintptr_t)ptr % expected_alignment == 0);
if (MDBX_UNALIGNED_OK || (expected_alignment % sizeof(uint16_t)) == 0)
@@ -100,7 +100,7 @@ unaligned_poke_u16(const unsigned expected_alignment,
memcpy(ptr, &v, sizeof(v));
}
__nothrow_pure_function static __always_inline uint32_t unaligned_peek_u32(
MDBX_NOTHROW_PURE_FUNCTION static __always_inline uint32_t unaligned_peek_u32(
const unsigned expected_alignment, const void *const __restrict ptr) {
assert((uintptr_t)ptr % expected_alignment == 0);
if (MDBX_UNALIGNED_OK || (expected_alignment % sizeof(uint32_t)) == 0)
@@ -132,7 +132,7 @@ unaligned_poke_u32(const unsigned expected_alignment,
memcpy(ptr, &v, sizeof(v));
}
__nothrow_pure_function static __always_inline uint64_t unaligned_peek_u64(
MDBX_NOTHROW_PURE_FUNCTION static __always_inline uint64_t unaligned_peek_u64(
const unsigned expected_alignment, const void *const __restrict ptr) {
assert((uintptr_t)ptr % expected_alignment == 0);
if (MDBX_UNALIGNED_OK || (expected_alignment % sizeof(uint64_t)) == 0)
@@ -185,7 +185,7 @@ unaligned_poke_u64(const unsigned expected_alignment,
unaligned_poke_u64(1, (char *)(ptr) + offsetof(struct, field), value)
/* Get the page number pointed to by a branch node */
__nothrow_pure_function static __always_inline pgno_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline pgno_t
node_pgno(const MDBX_node *const __restrict node) {
pgno_t pgno = UNALIGNED_PEEK_32(node, MDBX_node, mn_pgno32);
if (sizeof(pgno) > 4)
@@ -205,7 +205,7 @@ static __always_inline void node_set_pgno(MDBX_node *const __restrict node,
}
/* Get the size of the data in a leaf node */
__nothrow_pure_function static __always_inline size_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline size_t
node_ds(const MDBX_node *const __restrict node) {
return UNALIGNED_PEEK_32(node, MDBX_node, mn_dsize);
}
@@ -218,7 +218,7 @@ static __always_inline void node_set_ds(MDBX_node *const __restrict node,
}
/* The size of a key in a node */
__nothrow_pure_function static __always_inline size_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline size_t
node_ks(const MDBX_node *const __restrict node) {
return UNALIGNED_PEEK_16(node, MDBX_node, mn_ksize);
}
@@ -230,7 +230,7 @@ static __always_inline void node_set_ks(MDBX_node *const __restrict node,
UNALIGNED_POKE_16(node, MDBX_node, mn_ksize, (uint16_t)size);
}
__nothrow_pure_function static __always_inline uint8_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline uint8_t
node_flags(const MDBX_node *const __restrict node) {
return UNALIGNED_PEEK_8(node, MDBX_node, mn_flags);
}
@@ -244,29 +244,29 @@ static __always_inline void node_set_flags(MDBX_node *const __restrict node,
#define NODESIZE offsetof(MDBX_node, mn_data)
/* Address of the key for the node */
__nothrow_pure_function static __always_inline void *
MDBX_NOTHROW_PURE_FUNCTION static __always_inline void *
node_key(const MDBX_node *const __restrict node) {
return (char *)node + NODESIZE;
}
/* Address of the data for a node */
__nothrow_pure_function static __always_inline void *
MDBX_NOTHROW_PURE_FUNCTION static __always_inline void *
node_data(const MDBX_node *const __restrict node) {
return (char *)node_key(node) + node_ks(node);
}
/* Size of a node in a leaf page with a given key and data.
* This is node header plus key plus data size. */
__nothrow_const_function static __always_inline size_t
MDBX_NOTHROW_CONST_FUNCTION static __always_inline size_t
node_size_len(const size_t key_len, const size_t value_len) {
return NODESIZE + EVEN(key_len + value_len);
}
__nothrow_pure_function static __always_inline size_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline size_t
node_size(const MDBX_val *key, const MDBX_val *value) {
return node_size_len(key ? key->iov_len : 0, value ? value->iov_len : 0);
}
__nothrow_pure_function static __always_inline pgno_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline pgno_t
peek_pgno(const void *const __restrict ptr) {
if (sizeof(pgno_t) == sizeof(uint32_t))
return (pgno_t)unaligned_peek_u32(1, ptr);
@@ -289,7 +289,7 @@ static __always_inline void poke_pgno(void *const __restrict ptr,
memcpy(ptr, &pgno, sizeof(pgno));
}
__nothrow_pure_function static __always_inline pgno_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline pgno_t
node_largedata_pgno(const MDBX_node *const __restrict node) {
assert(node_flags(node) & F_BIGDATA);
return peek_pgno(node_data(node));
@@ -411,7 +411,7 @@ __cold intptr_t mdbx_limits_valsize_max(intptr_t pagesize,
* size will only include the key and not the data. Sizes are always
* rounded up to an even number of bytes, to guarantee 2-byte alignment
* of the MDBX_node headers. */
__nothrow_pure_function static __always_inline size_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline size_t
leaf_size(const MDBX_env *env, const MDBX_val *key, const MDBX_val *data) {
size_t node_bytes = node_size(key, data);
/* NOTE: The actual limit is LEAF_NODEMAX(env->me_psize), but it reasonable to
@@ -454,7 +454,7 @@ leaf_size(const MDBX_env *env, const MDBX_val *key, const MDBX_val *data) {
* [in] key The key for the node.
*
* Returns The number of bytes needed to store the node. */
__nothrow_pure_function static __always_inline size_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline size_t
branch_size(const MDBX_env *env, const MDBX_val *key) {
/* Size of a node in a branch page with a given key.
* This is just the node header plus the key, there is no data. */
@@ -470,7 +470,7 @@ branch_size(const MDBX_env *env, const MDBX_val *key) {
return node_bytes + sizeof(indx_t);
}
__nothrow_const_function static __always_inline uint16_t
MDBX_NOTHROW_CONST_FUNCTION static __always_inline uint16_t
flags_db2sub(uint16_t db_flags) {
uint16_t sub_flags = db_flags & MDBX_DUPFIXED;
@@ -491,84 +491,84 @@ flags_db2sub(uint16_t db_flags) {
/*----------------------------------------------------------------------------*/
__nothrow_pure_function static __always_inline size_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline size_t
pgno2bytes(const MDBX_env *env, pgno_t pgno) {
mdbx_assert(env, (1u << env->me_psize2log) == env->me_psize);
return ((size_t)pgno) << env->me_psize2log;
}
__nothrow_pure_function static __always_inline MDBX_page *
MDBX_NOTHROW_PURE_FUNCTION static __always_inline MDBX_page *
pgno2page(const MDBX_env *env, pgno_t pgno) {
return (MDBX_page *)(env->me_map + pgno2bytes(env, pgno));
}
__nothrow_pure_function static __always_inline pgno_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline pgno_t
bytes2pgno(const MDBX_env *env, size_t bytes) {
mdbx_assert(env, (env->me_psize >> env->me_psize2log) == 1);
return (pgno_t)(bytes >> env->me_psize2log);
}
__nothrow_pure_function static size_t pgno_align2os_bytes(const MDBX_env *env,
pgno_t pgno) {
MDBX_NOTHROW_PURE_FUNCTION static size_t
pgno_align2os_bytes(const MDBX_env *env, pgno_t pgno) {
return ceil_powerof2(pgno2bytes(env, pgno), env->me_os_psize);
}
__nothrow_pure_function static pgno_t pgno_align2os_pgno(const MDBX_env *env,
pgno_t pgno) {
MDBX_NOTHROW_PURE_FUNCTION static pgno_t pgno_align2os_pgno(const MDBX_env *env,
pgno_t pgno) {
return bytes2pgno(env, pgno_align2os_bytes(env, pgno));
}
__nothrow_pure_function static size_t bytes_align2os_bytes(const MDBX_env *env,
size_t bytes) {
MDBX_NOTHROW_PURE_FUNCTION static size_t
bytes_align2os_bytes(const MDBX_env *env, size_t bytes) {
return ceil_powerof2(ceil_powerof2(bytes, env->me_psize), env->me_os_psize);
}
/* Address of first usable data byte in a page, after the header */
__nothrow_pure_function static __always_inline void *
MDBX_NOTHROW_PURE_FUNCTION static __always_inline void *
page_data(const MDBX_page *mp) {
return (char *)mp + PAGEHDRSZ;
}
__nothrow_pure_function static __always_inline const MDBX_page *
MDBX_NOTHROW_PURE_FUNCTION static __always_inline const MDBX_page *
data_page(const void *data) {
return container_of(data, MDBX_page, mp_ptrs);
}
__nothrow_pure_function static __always_inline MDBX_meta *
MDBX_NOTHROW_PURE_FUNCTION static __always_inline MDBX_meta *
page_meta(MDBX_page *mp) {
return (MDBX_meta *)page_data(mp);
}
/* Number of nodes on a page */
__nothrow_pure_function static __always_inline unsigned
MDBX_NOTHROW_PURE_FUNCTION static __always_inline unsigned
page_numkeys(const MDBX_page *mp) {
return mp->mp_lower >> 1;
}
/* The amount of space remaining in the page */
__nothrow_pure_function static __always_inline unsigned
MDBX_NOTHROW_PURE_FUNCTION static __always_inline unsigned
page_room(const MDBX_page *mp) {
return mp->mp_upper - mp->mp_lower;
}
__nothrow_pure_function static __always_inline unsigned
MDBX_NOTHROW_PURE_FUNCTION static __always_inline unsigned
page_space(const MDBX_env *env) {
STATIC_ASSERT(PAGEHDRSZ % 2 == 0);
return env->me_psize - PAGEHDRSZ;
}
__nothrow_pure_function static __always_inline unsigned
MDBX_NOTHROW_PURE_FUNCTION static __always_inline unsigned
page_used(const MDBX_env *env, const MDBX_page *mp) {
return page_space(env) - page_room(mp);
}
/* The percentage of space used in the page, in a percents. */
__nothrow_pure_function static __maybe_unused __inline double
MDBX_NOTHROW_PURE_FUNCTION static __maybe_unused __inline double
page_fill(const MDBX_env *env, const MDBX_page *mp) {
return page_used(env, mp) * 100.0 / page_space(env);
}
__nothrow_pure_function static __inline bool
MDBX_NOTHROW_PURE_FUNCTION static __inline bool
page_fill_enough(const MDBX_page *mp, unsigned spaceleft_threshold,
unsigned minkeys_threshold) {
return page_room(mp) < spaceleft_threshold &&
@@ -576,12 +576,12 @@ page_fill_enough(const MDBX_page *mp, unsigned spaceleft_threshold,
}
/* The number of overflow pages needed to store the given size. */
__nothrow_pure_function static __always_inline pgno_t
MDBX_NOTHROW_PURE_FUNCTION static __always_inline pgno_t
number_of_ovpages(const MDBX_env *env, size_t bytes) {
return bytes2pgno(env, PAGEHDRSZ - 1 + bytes) + 1;
}
__cold static int mdbx_printf_args(2, 3)
__cold static int MDBX_PRINTF_ARGS(2, 3)
bad_page(const MDBX_page *mp, const char *fmt, ...) {
if (mdbx_log_enabled(MDBX_LOG_ERROR)) {
static const MDBX_page *prev;
@@ -601,7 +601,7 @@ __cold static int mdbx_printf_args(2, 3)
}
/* Address of node i in page p */
__nothrow_pure_function static __always_inline MDBX_node *
MDBX_NOTHROW_PURE_FUNCTION static __always_inline MDBX_node *
page_node(const MDBX_page *mp, unsigned i) {
assert((mp->mp_flags & (P_LEAF2 | P_OVERFLOW | P_META)) == 0);
assert(page_numkeys(mp) > (unsigned)(i));
@@ -612,7 +612,7 @@ page_node(const MDBX_page *mp, unsigned i) {
/* The address of a key in a LEAF2 page.
* LEAF2 pages are used for MDBX_DUPFIXED sorted-duplicate sub-DBs.
* There are no node headers, keys are stored contiguously. */
__nothrow_pure_function static __always_inline void *
MDBX_NOTHROW_PURE_FUNCTION static __always_inline void *
page_leaf2key(const MDBX_page *mp, unsigned i, size_t keysize) {
assert((mp->mp_flags & (P_BRANCH | P_LEAF | P_LEAF2 | P_OVERFLOW | P_META)) ==
(P_LEAF | P_LEAF2));
@@ -1383,7 +1383,7 @@ static __inline void lcklist_unlock(void) {
#endif
}
__nothrow_const_function static uint64_t rrxmrrxmsx_0(uint64_t v) {
MDBX_NOTHROW_CONST_FUNCTION static uint64_t rrxmrrxmsx_0(uint64_t v) {
/* Pelle Evensen's mixer, https://bit.ly/2HOfynt */
v ^= (v << 39 | v >> 25) ^ (v << 14 | v >> 50);
v *= UINT64_C(0xA24BAED4963EE407);

View File

@@ -151,18 +151,6 @@
# endif
#endif /* __prefetch */
#ifndef __noreturn
# ifdef _Noreturn
# define __noreturn _Noreturn
# elif defined(__GNUC__) || __has_attribute(__noreturn__)
# define __noreturn __attribute__((__noreturn__))
# elif defined(_MSC_VER)
# define __noreturn __declspec(noreturn)
# else
# define __noreturn
# endif
#endif /* __noreturn */
#ifndef __nothrow
# if defined(__cplusplus)
# if __cplusplus < 201703L
@@ -268,7 +256,7 @@
#endif /* __anonymous_struct_extension__ */
#ifndef __Wpedantic_format_voidptr
static __inline __maybe_unused const void* __pure_function
static __inline __maybe_unused const void* MDBX_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

@@ -1038,9 +1038,9 @@ extern uint8_t mdbx_runtime_flags;
extern uint8_t mdbx_loglevel;
extern MDBX_debug_func *mdbx_debug_logger;
MDBX_INTERNAL_FUNC void mdbx_printf_args(4, 5)
MDBX_INTERNAL_FUNC void MDBX_PRINTF_ARGS(4, 5)
mdbx_debug_log(int level, const char *function, int line, const char *fmt,
...) mdbx_printf_args(4, 5);
...) MDBX_PRINTF_ARGS(4, 5);
MDBX_INTERNAL_FUNC void mdbx_debug_log_va(int level, const char *function,
int line, const char *fmt,
va_list args);
@@ -1360,30 +1360,30 @@ typedef struct MDBX_node {
/* Do not spill pages to disk if txn is getting full, may fail instead */
#define MDBX_NOSPILL 0x8000
__nothrow_const_function static __maybe_unused __inline pgno_t
MDBX_NOTHROW_CONST_FUNCTION static __maybe_unused __inline pgno_t
pgno_add(pgno_t base, pgno_t augend) {
assert(base <= MAX_PAGENO);
return (augend < MAX_PAGENO - base) ? base + augend : MAX_PAGENO;
}
__nothrow_const_function static __maybe_unused __inline pgno_t
MDBX_NOTHROW_CONST_FUNCTION static __maybe_unused __inline pgno_t
pgno_sub(pgno_t base, pgno_t subtrahend) {
assert(base >= MIN_PAGENO);
return (subtrahend < base - MIN_PAGENO) ? base - subtrahend : MIN_PAGENO;
}
__nothrow_const_function static __always_inline __maybe_unused bool
MDBX_NOTHROW_CONST_FUNCTION static __always_inline __maybe_unused bool
is_powerof2(size_t x) {
return (x & (x - 1)) == 0;
}
__nothrow_const_function static __always_inline __maybe_unused size_t
MDBX_NOTHROW_CONST_FUNCTION static __always_inline __maybe_unused size_t
floor_powerof2(size_t value, size_t granularity) {
assert(is_powerof2(granularity));
return value & ~(granularity - 1);
}
__nothrow_const_function static __always_inline __maybe_unused size_t
MDBX_NOTHROW_CONST_FUNCTION static __always_inline __maybe_unused size_t
ceil_powerof2(size_t value, size_t granularity) {
return floor_powerof2(value + granularity - 1, granularity);
}

View File

@@ -28,14 +28,6 @@
#include <cctype> // for isxdigit(), etc
#include <system_error>
#if defined(__has_include) && __has_include(<version>)
#include <version>
#endif
#if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
#include <filesystem>
#endif /* __cpp_lib_filesystem >= 201703L */
namespace {
#if 0 /* Unused for now */
@@ -72,7 +64,7 @@ class trouble_location {
#endif
public:
cxx11_constexpr trouble_location(unsigned line, const char *condition,
MDBX_CXX11_CONSTEXPR trouble_location(unsigned line, const char *condition,
const char *function, const char *filename)
:
#if TROUBLE_PROVIDE_LINENO
@@ -198,14 +190,14 @@ __cold bug::~bug() noexcept {}
#define RAISE_BUG(line, condition, function, file) \
do { \
static cxx11_constexpr_var trouble_location bug(line, condition, function, \
file); \
static MDBX_CXX11_CONSTEXPR_VAR trouble_location bug(line, condition, \
function, file); \
raise_bug(bug); \
} while (0)
#define ENSURE(condition) \
do \
if (mdbx_unlikely(!(condition))) \
if (MDBX_UNLIKELY(!(condition))) \
RAISE_BUG(__LINE__, #condition, __func__, __FILE__); \
while (0)
@@ -488,9 +480,9 @@ bool slice::is_printable(bool disable_utf8) const noexcept {
auto src = byte_ptr();
const auto end = src + length();
if (mdbx_unlikely(disable_utf8)) {
if (MDBX_UNLIKELY(disable_utf8)) {
do
if (mdbx_unlikely((P_ & map[*src]) == 0))
if (MDBX_UNLIKELY((P_ & map[*src]) == 0))
return false;
while (++src < end);
return true;
@@ -543,7 +535,7 @@ bool slice::is_printable(bool disable_utf8) const noexcept {
char *slice::to_hex(char *__restrict dest, size_t dest_size, bool uppercase,
unsigned wrap_width) const {
if (mdbx_unlikely(to_hex_bytes(wrap_width) > dest_size))
if (MDBX_UNLIKELY(to_hex_bytes(wrap_width) > dest_size))
throw_too_small_target_buffer();
auto src = byte_ptr();
@@ -565,22 +557,22 @@ char *slice::to_hex(char *__restrict dest, size_t dest_size, bool uppercase,
byte *slice::from_hex(byte *__restrict dest, size_t dest_size,
bool ignore_spaces) const {
if (mdbx_unlikely(length() % 2 && !ignore_spaces))
if (MDBX_UNLIKELY(length() % 2 && !ignore_spaces))
throw std::domain_error(
"mdbx::from_hex:: odd length of hexadecimal string");
if (mdbx_unlikely(from_hex_bytes() > dest_size))
if (MDBX_UNLIKELY(from_hex_bytes() > dest_size))
throw_too_small_target_buffer();
auto src = byte_ptr();
for (auto left = length(); left > 0;) {
if (mdbx_unlikely(*src <= ' ') &&
mdbx_likely(ignore_spaces && isspace(*src))) {
if (MDBX_UNLIKELY(*src <= ' ') &&
MDBX_LIKELY(ignore_spaces && isspace(*src))) {
++src;
--left;
continue;
}
if (mdbx_unlikely(left < 1 || !isxdigit(src[0]) || !isxdigit(src[1])))
if (MDBX_UNLIKELY(left < 1 || !isxdigit(src[0]) || !isxdigit(src[1])))
throw std::domain_error("mdbx::from_hex:: invalid hexadecimal string");
int8_t hi = src[0];
@@ -599,20 +591,20 @@ byte *slice::from_hex(byte *__restrict dest, size_t dest_size,
}
bool slice::is_hex(bool ignore_spaces) const noexcept {
if (mdbx_unlikely(length() % 2 && !ignore_spaces))
if (MDBX_UNLIKELY(length() % 2 && !ignore_spaces))
return false;
bool got = false;
auto src = byte_ptr();
for (auto left = length(); left > 0;) {
if (mdbx_unlikely(*src <= ' ') &&
mdbx_likely(ignore_spaces && isspace(*src))) {
if (MDBX_UNLIKELY(*src <= ' ') &&
MDBX_LIKELY(ignore_spaces && isspace(*src))) {
++src;
--left;
continue;
}
if (mdbx_unlikely(left < 1 || !isxdigit(src[0]) || !isxdigit(src[1])))
if (MDBX_UNLIKELY(left < 1 || !isxdigit(src[0]) || !isxdigit(src[1])))
return false;
got = true;
@@ -669,13 +661,13 @@ static inline char b58_8to11(uint64_t &v) noexcept {
char *slice::to_base58(char *__restrict dest, size_t dest_size,
unsigned wrap_width) const {
if (mdbx_unlikely(to_base58_bytes(wrap_width) > dest_size))
if (MDBX_UNLIKELY(to_base58_bytes(wrap_width) > dest_size))
throw_too_small_target_buffer();
auto src = byte_ptr();
size_t left = length();
auto line = dest;
while (mdbx_likely(left > 7)) {
while (MDBX_LIKELY(left > 7)) {
left -= 8;
uint64_t v;
std::memcpy(&v, src, 8);
@@ -752,20 +744,20 @@ static inline signed char b58_11to8(uint64_t &v, const byte c) noexcept {
byte *slice::from_base58(byte *__restrict dest, size_t dest_size,
bool ignore_spaces) const {
if (mdbx_unlikely(from_base58_bytes() > dest_size))
if (MDBX_UNLIKELY(from_base58_bytes() > dest_size))
throw_too_small_target_buffer();
auto src = byte_ptr();
for (auto left = length(); left > 0;) {
if (mdbx_unlikely(isspace(*src)) && ignore_spaces) {
if (MDBX_UNLIKELY(isspace(*src)) && ignore_spaces) {
++src;
--left;
continue;
}
if (mdbx_likely(left > 10)) {
if (MDBX_LIKELY(left > 10)) {
uint64_t v = 0;
if (mdbx_unlikely((b58_11to8(v, src[0]) | b58_11to8(v, src[1]) |
if (MDBX_UNLIKELY((b58_11to8(v, src[0]) | b58_11to8(v, src[1]) |
b58_11to8(v, src[2]) | b58_11to8(v, src[3]) |
b58_11to8(v, src[4]) | b58_11to8(v, src[5]) |
b58_11to8(v, src[6]) | b58_11to8(v, src[7]) |
@@ -792,7 +784,7 @@ byte *slice::from_base58(byte *__restrict dest, size_t dest_size,
uint64_t v = 1;
unsigned parrots = 0;
do {
if (mdbx_unlikely(b58_11to8(v, *src++) < 0))
if (MDBX_UNLIKELY(b58_11to8(v, *src++) < 0))
goto bailout;
parrots += 32;
} while (--left);
@@ -814,15 +806,15 @@ bool slice::is_base58(bool ignore_spaces) const noexcept {
bool got = false;
auto src = byte_ptr();
for (auto left = length(); left > 0;) {
if (mdbx_unlikely(*src <= ' ') &&
mdbx_likely(ignore_spaces && isspace(*src))) {
if (MDBX_UNLIKELY(*src <= ' ') &&
MDBX_LIKELY(ignore_spaces && isspace(*src))) {
++src;
--left;
continue;
}
if (mdbx_likely(left > 10)) {
if (mdbx_unlikely((b58_map[src[0]] | b58_map[src[1]] | b58_map[src[2]] |
if (MDBX_LIKELY(left > 10)) {
if (MDBX_UNLIKELY((b58_map[src[0]] | b58_map[src[1]] | b58_map[src[2]] |
b58_map[src[3]] | b58_map[src[4]] | b58_map[src[5]] |
b58_map[src[6]] | b58_map[src[7]] | b58_map[src[8]] |
b58_map[src[9]] | b58_map[src[10]]) < 0))
@@ -838,7 +830,7 @@ bool slice::is_base58(bool ignore_spaces) const noexcept {
return false;
do
if (mdbx_unlikely(b58_map[*src++] < 0))
if (MDBX_UNLIKELY(b58_map[*src++] < 0))
return false;
while (--left);
got = true;
@@ -865,7 +857,7 @@ static inline void b64_3to4(const byte x, const byte y, const byte z,
char *slice::to_base64(char *__restrict dest, size_t dest_size,
unsigned wrap_width) const {
if (mdbx_unlikely(to_base64_bytes(wrap_width) > dest_size))
if (MDBX_UNLIKELY(to_base64_bytes(wrap_width) > dest_size))
throw_too_small_target_buffer();
auto src = byte_ptr();
@@ -874,7 +866,7 @@ char *slice::to_base64(char *__restrict dest, size_t dest_size,
while (true) {
switch (left) {
default:
cxx20_attribute_likely left -= 3;
MDBX_CXX20_LIKELY left -= 3;
b64_3to4(src[0], src[1], src[2], dest);
dest += 4;
src += 3;
@@ -928,27 +920,27 @@ static inline signed char b64_4to3(signed char a, signed char b, signed char c,
byte *slice::from_base64(byte *__restrict dest, size_t dest_size,
bool ignore_spaces) const {
if (mdbx_unlikely(length() % 4 && !ignore_spaces))
if (MDBX_UNLIKELY(length() % 4 && !ignore_spaces))
throw std::domain_error("mdbx::from_base64:: odd length of base64 string");
if (mdbx_unlikely(from_base64_bytes() > dest_size))
if (MDBX_UNLIKELY(from_base64_bytes() > dest_size))
throw_too_small_target_buffer();
auto src = byte_ptr();
for (auto left = length(); left > 0;) {
if (mdbx_unlikely(*src <= ' ') &&
mdbx_likely(ignore_spaces && isspace(*src))) {
if (MDBX_UNLIKELY(*src <= ' ') &&
MDBX_LIKELY(ignore_spaces && isspace(*src))) {
++src;
--left;
continue;
}
if (mdbx_unlikely(left < 3)) {
if (MDBX_UNLIKELY(left < 3)) {
bailout:
throw std::domain_error("mdbx::from_base64:: invalid base64 string");
}
const signed char a = b64_map[src[0]], b = b64_map[src[1]],
c = b64_map[src[2]], d = b64_map[src[3]];
if (mdbx_unlikely(b64_4to3(a, b, c, d, dest) < 0)) {
if (MDBX_UNLIKELY(b64_4to3(a, b, c, d, dest) < 0)) {
if (left == 4 && (a | b) >= 0 && d == EQ) {
if (c >= 0)
return dest + 2;
@@ -964,24 +956,24 @@ byte *slice::from_base64(byte *__restrict dest, size_t dest_size,
}
bool slice::is_base64(bool ignore_spaces) const noexcept {
if (mdbx_unlikely(length() % 4 && !ignore_spaces))
if (MDBX_UNLIKELY(length() % 4 && !ignore_spaces))
return false;
bool got = false;
auto src = byte_ptr();
for (auto left = length(); left > 0;) {
if (mdbx_unlikely(*src <= ' ') &&
mdbx_likely(ignore_spaces && isspace(*src))) {
if (MDBX_UNLIKELY(*src <= ' ') &&
MDBX_LIKELY(ignore_spaces && isspace(*src))) {
++src;
--left;
continue;
}
if (mdbx_unlikely(left < 3))
if (MDBX_UNLIKELY(left < 3))
return false;
const signed char a = b64_map[src[0]], b = b64_map[src[1]],
c = b64_map[src[2]], d = b64_map[src[3]];
if (mdbx_unlikely((a | b | c | d) < 0)) {
if (MDBX_UNLIKELY((a | b | c | d) < 0)) {
if (left == 4 && (a | b) >= 0 && d == EQ && (c >= 0 || c == d))
return true;
return false;
@@ -1008,7 +1000,7 @@ size_t env::default_pagesize() noexcept { return ::mdbx_syspagesize(); }
static inline MDBX_env_flags_t mode2flags(env::mode mode) {
switch (mode) {
default:
cxx20_attribute_unlikely throw std::invalid_argument("db::mode is invalid");
MDBX_CXX20_UNLIKELY throw std::invalid_argument("db::mode is invalid");
case env::mode::readonly:
return MDBX_RDONLY;
case env::mode::write_file_io:
@@ -1043,7 +1035,7 @@ env::operate_parameters::make_flags(bool accede, bool use_subdirectory) const {
flags |= MDBX_LIFORECLAIM;
switch (durability) {
default:
cxx20_attribute_unlikely throw std::invalid_argument(
MDBX_CXX20_UNLIKELY throw std::invalid_argument(
"db::durability is invalid");
case env::durability::robust_synchronous:
break;
@@ -1221,7 +1213,7 @@ txn_managed::~txn_managed() noexcept {
void txn_managed::abort() {
const error err = static_cast<MDBX_error_t>(::mdbx_txn_abort(handle_));
if (mdbx_unlikely(err.code() != MDBX_SUCCESS)) {
if (MDBX_UNLIKELY(err.code() != MDBX_SUCCESS)) {
if (err.code() != MDBX_THREAD_MISMATCH)
handle_ = nullptr;
err.throw_exception();
@@ -1230,7 +1222,7 @@ void txn_managed::abort() {
void txn_managed::commit() {
const error err = static_cast<MDBX_error_t>(::mdbx_txn_commit(handle_));
if (mdbx_unlikely(err.code() != MDBX_SUCCESS)) {
if (MDBX_UNLIKELY(err.code() != MDBX_SUCCESS)) {
if (err.code() != MDBX_THREAD_MISMATCH)
handle_ = nullptr;
err.throw_exception();
@@ -1250,9 +1242,9 @@ bool txn::drop_map(const char *name, bool throw_if_absent) {
case MDBX_BAD_DBI:
if (!throw_if_absent)
return false;
cxx17_attribute_fallthrough /* fallthrough */;
MDBX_CXX17_FALLTHROUGH /* fallthrough */;
default:
cxx20_attribute_unlikely error::throw_exception(err);
MDBX_CXX20_UNLIKELY error::throw_exception(err);
}
}
@@ -1267,17 +1259,17 @@ bool txn::clear_map(const char *name, bool throw_if_absent) {
case MDBX_BAD_DBI:
if (!throw_if_absent)
return false;
cxx17_attribute_fallthrough /* fallthrough */;
MDBX_CXX17_FALLTHROUGH /* fallthrough */;
default:
cxx20_attribute_unlikely error::throw_exception(err);
MDBX_CXX20_UNLIKELY error::throw_exception(err);
}
}
//------------------------------------------------------------------------------
void cursor_managed::close() {
if (mdbx_unlikely(!handle_))
cxx20_attribute_unlikely error::throw_exception(MDBX_EINVAL);
if (MDBX_UNLIKELY(!handle_))
MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_EINVAL);
::mdbx_cursor_close(handle_);
handle_ = nullptr;
}

View File

@@ -106,7 +106,7 @@ struct problem {
struct problem *problems_list;
uint64_t total_problems;
static void mdbx_printf_args(1, 2) print(const char *msg, ...) {
static void MDBX_PRINTF_ARGS(1, 2) print(const char *msg, ...) {
if (!quiet) {
va_list args;
@@ -145,7 +145,7 @@ static void va_log(MDBX_log_level_t level, const char *msg, va_list args) {
}
}
static void mdbx_printf_args(1, 2) error(const char *msg, ...) {
static void MDBX_PRINTF_ARGS(1, 2) error(const char *msg, ...) {
va_list args;
va_start(args, msg);
va_log(MDBX_LOG_ERROR, msg, args);
@@ -216,7 +216,7 @@ static walk_dbi_t *pagemap_lookup_dbi(const char *dbi_name, bool silent) {
return last = dbi;
}
static void mdbx_printf_args(4, 5)
static void MDBX_PRINTF_ARGS(4, 5)
problem_add(const char *object, uint64_t entry_number, const char *msg,
const char *extra, ...) {

View File

@@ -145,7 +145,7 @@ __extern_C void __assert_fail(const char *assertion, const char *file,
#else
__nothrow
#endif /* __THROW */
__noreturn;
MDBX_NORETURN;
#elif defined(__APPLE__) || defined(__MACH__)
__extern_C void __assert_rtn(const char *function, const char *file, int line,
@@ -153,7 +153,7 @@ __extern_C void __assert_rtn(const char *function, const char *file, int line,
#ifdef __dead2
__dead2
#else
__noreturn
MDBX_NORETURN
#endif /* __dead2 */
#ifdef __disable_tail_calls
__disable_tail_calls
@@ -164,7 +164,7 @@ __extern_C void __assert_rtn(const char *function, const char *file, int line,
__assert_rtn(function, file, line, assertion)
#elif defined(__sun) || defined(__SVR4) || defined(__svr4__)
__extern_C void __assert_c99(const char *assection, const char *file, int line,
const char *function) __noreturn;
const char *function) MDBX_NORETURN;
#define __assert_fail(assertion, file, line, function) \
__assert_c99(assertion, file, line, function)
#elif defined(__OpenBSD__)
@@ -186,7 +186,7 @@ __extern_C void __assert(const char *function, const char *file, int line,
#ifdef __dead2
__dead2
#else
__noreturn
MDBX_NORETURN
#endif /* __dead2 */
#ifdef __disable_tail_calls
__disable_tail_calls

View File

@@ -412,7 +412,7 @@ typedef pthread_mutex_t mdbx_fastmutex_t;
/* Get the size of a memory page for the system.
* This is the basic size that the platform's memory manager uses, and is
* fundamental to the use of memory-mapped files. */
__nothrow_const_function static __maybe_unused __inline size_t
MDBX_NOTHROW_CONST_FUNCTION static __maybe_unused __inline size_t
mdbx_syspagesize(void) {
#if defined(_WIN32) || defined(_WIN64)
SYSTEM_INFO si;
@@ -536,7 +536,7 @@ static __maybe_unused __inline void mdbx_memory_barrier(void) {
#define mdbx_asprintf asprintf
#define mdbx_vasprintf vasprintf
#else
MDBX_INTERNAL_FUNC mdbx_printf_args(2, 3) int __maybe_unused
MDBX_INTERNAL_FUNC MDBX_PRINTF_ARGS(2, 3) int __maybe_unused
mdbx_asprintf(char **strp, const char *fmt, ...);
MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt, va_list ap);
#endif