mirror of
https://github.com/isar/libmdbx.git
synced 2025-12-15 04:32:21 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64904f0cab | ||
|
|
47a80b23f3 | ||
|
|
aee4971a2f | ||
|
|
77ac97879a | ||
|
|
0ec2758784 | ||
|
|
5598ec9a98 | ||
|
|
73215bdcc7 |
@@ -767,9 +767,9 @@ $(DIST_DIR)/mdbx.c: $(DIST_DIR)/@tmp-internals.inc $(lastword $(MAKEFILE_LIST))
|
||||
) | $(SED) -e '/#include "/d;/#pragma once/d' -e 's|@INCLUDE|#include|' \
|
||||
-e '/ clang-format o/d;/ \*INDENT-O/d' -e '3i /* clang-format off */' | cat -s >$@
|
||||
|
||||
$(DIST_DIR)/mdbx.c++: $(DIST_DIR)/@tmp-essentials.inc src/mdbx.c++ $(lastword $(MAKEFILE_LIST))
|
||||
$(DIST_DIR)/mdbx.c++: $(DIST_DIR)/@tmp-internals.inc src/mdbx.c++ $(lastword $(MAKEFILE_LIST))
|
||||
@echo ' MAKE $@'
|
||||
$(QUIET)cat $(DIST_DIR)/@tmp-essentials.inc src/mdbx.c++ | $(SED) \
|
||||
$(QUIET)cat $(DIST_DIR)/@tmp-internals.inc src/mdbx.c++ | $(SED) \
|
||||
-e '/#define xMDBX_ALLOY/d' \
|
||||
-e '/#include "/d;/#pragma once/d' \
|
||||
-e 's|@INCLUDE|#include|;s|"mdbx.h"|"mdbx.h++"|' \
|
||||
|
||||
26
mdbx.h++
26
mdbx.h++
@@ -370,6 +370,9 @@ class txn_managed;
|
||||
class cursor;
|
||||
class cursor_managed;
|
||||
|
||||
/// \brief Transaction ID and MVCC-snapshot number.
|
||||
using txnid = uint64_t;
|
||||
|
||||
/// \brief Default buffer.
|
||||
using default_buffer = buffer<default_allocator, default_capacity_policy>;
|
||||
|
||||
@@ -997,6 +1000,9 @@ struct LIBMDBX_API_TYPE slice : public ::MDBX_val {
|
||||
friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept;
|
||||
friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept;
|
||||
friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept;
|
||||
#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
|
||||
friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept;
|
||||
#endif /* __cpp_impl_three_way_comparison */
|
||||
|
||||
/// \brief Checks the slice is not refers to null address or has zero length.
|
||||
MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); }
|
||||
@@ -2753,6 +2759,9 @@ struct pair {
|
||||
friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept;
|
||||
friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept;
|
||||
friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept;
|
||||
#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
|
||||
friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept;
|
||||
#endif /* __cpp_impl_three_way_comparison */
|
||||
};
|
||||
|
||||
/// \brief Combines pair of slices for key and value with boolean flag to
|
||||
@@ -4478,6 +4487,11 @@ public:
|
||||
inline void upsert(const slice &key, const slice &value);
|
||||
inline slice upsert_reserve(const slice &key, size_t value_length);
|
||||
|
||||
/// \brief Updates value associated with a key at the current cursor position.
|
||||
void update_current(const slice &value);
|
||||
/// \brief Reserves and returns the space to storing a value associated with a key at the current cursor position.
|
||||
slice reverse_current(size_t value_length);
|
||||
|
||||
inline void update(const slice &key, const slice &value);
|
||||
inline bool try_update(const slice &key, const slice &value);
|
||||
inline slice update_reserve(const slice &key, size_t value_length);
|
||||
@@ -5011,6 +5025,12 @@ MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a,
|
||||
return slice::compare_fast(a, b) != 0;
|
||||
}
|
||||
|
||||
#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
|
||||
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept {
|
||||
return slice::compare_lexicographically(a, b);
|
||||
}
|
||||
#endif /* __cpp_impl_three_way_comparison */
|
||||
|
||||
template <class ALLOCATOR>
|
||||
inline string<ALLOCATOR> slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &allocator) const {
|
||||
return to_hex(*this, uppercase, wrap_width).as_string<ALLOCATOR>(allocator);
|
||||
@@ -5109,6 +5129,12 @@ MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, c
|
||||
memcmp(a.value.data(), b.value.data(), a.value.length()) != 0;
|
||||
}
|
||||
|
||||
#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
|
||||
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept {
|
||||
return pair::compare_lexicographically(a, b);
|
||||
}
|
||||
#endif /* __cpp_impl_three_way_comparison */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template <class ALLOCATOR, typename CAPACITY_POLICY>
|
||||
|
||||
@@ -249,6 +249,8 @@ __dll_export
|
||||
#else
|
||||
#if defined(__ANDROID_API__)
|
||||
"Android" MDBX_STRINGIFY(__ANDROID_API__)
|
||||
#elif defined(__OHOS__)
|
||||
"Harmony OS"
|
||||
#elif defined(__linux__) || defined(__gnu_linux__)
|
||||
"Linux"
|
||||
#elif defined(EMSCRIPTEN) || defined(__EMSCRIPTEN__)
|
||||
@@ -296,7 +298,9 @@ __dll_export
|
||||
|
||||
"-"
|
||||
|
||||
#if defined(__amd64__)
|
||||
#if defined(__e2k__) || defined(__elbrus__)
|
||||
"Elbrus"
|
||||
#elif defined(__amd64__)
|
||||
"AMD64"
|
||||
#elif defined(__ia32__)
|
||||
"IA32"
|
||||
@@ -333,6 +337,8 @@ __dll_export
|
||||
"SPARC"
|
||||
#elif defined(__s390__) || defined(__s390) || defined(__zarch__) || defined(__zarch)
|
||||
"S390"
|
||||
#elif defined(__riscv) || defined(__riscv__) || defined(__RISCV) || defined(__RISCV__)
|
||||
"RISC-V (стеклянные бусы)"
|
||||
#else
|
||||
"UnknownARCH"
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
|
||||
#include "essentials.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#if _MSC_VER > 1913
|
||||
#pragma warning(disable : 5054) /* deprecated between enumerations of different types */
|
||||
#endif
|
||||
#endif /* MSVC */
|
||||
|
||||
typedef struct dp dp_t;
|
||||
typedef struct dpl dpl_t;
|
||||
typedef struct kvx kvx_t;
|
||||
@@ -561,6 +568,8 @@ MDBX_MAYBE_UNUSED static void static_checks(void) {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
#include "node.h"
|
||||
|
||||
#include "dbi.h"
|
||||
@@ -588,3 +597,9 @@ MDBX_MAYBE_UNUSED static void static_checks(void) {
|
||||
#include "walk.h"
|
||||
|
||||
#include "sort.h"
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif /* MSVC */
|
||||
|
||||
24
src/mdbx.c++
24
src/mdbx.c++
@@ -27,6 +27,8 @@
|
||||
#include <cctype> // for isxdigit(), etc
|
||||
#include <system_error>
|
||||
|
||||
#include "internals.h"
|
||||
|
||||
namespace {
|
||||
|
||||
#if 0 /* Unused for now */
|
||||
@@ -1492,7 +1494,7 @@ void txn_managed::commit(commit_latency *latency) {
|
||||
}
|
||||
|
||||
void txn_managed::commit_embark_read() {
|
||||
auto env = this->env();
|
||||
auto env = handle_->env;
|
||||
commit();
|
||||
error::success_or_throw(::mdbx_txn_begin(env, nullptr, MDBX_TXN_RDONLY, &handle_));
|
||||
}
|
||||
@@ -1607,6 +1609,26 @@ __cold bool txn::rename_map(const ::std::string &old_name, const ::std::string &
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void cursor::update_current(const slice &value) {
|
||||
default_buffer holder;
|
||||
auto key = current().key;
|
||||
if (error::boolean_or_throw(mdbx_is_dirty(handle_->txn, key.iov_base)))
|
||||
key = holder.assign(key);
|
||||
|
||||
update(key, value);
|
||||
}
|
||||
|
||||
slice cursor::reverse_current(size_t value_length) {
|
||||
default_buffer holder;
|
||||
auto key = current().key;
|
||||
if (error::boolean_or_throw(mdbx_is_dirty(handle_->txn, key.iov_base)))
|
||||
key = holder.assign(key);
|
||||
|
||||
return update_reserve(key, value_length);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
__cold ::std::ostream &operator<<(::std::ostream &out, const slice &it) {
|
||||
out << "{";
|
||||
if (!it.is_valid())
|
||||
|
||||
@@ -31,7 +31,7 @@ MDBX_INTERNAL int __must_check_result dxb_sync_locked(MDBX_env *env, unsigned fl
|
||||
#if defined(ENABLE_MEMCHECK) || defined(__SANITIZE_ADDRESS__)
|
||||
MDBX_INTERNAL void dxb_sanitize_tail(MDBX_env *env, MDBX_txn *txn);
|
||||
#else
|
||||
static inline void dxb_sanitize_tail(MDBX_env *env, MDBX_txn *txn) {
|
||||
MDBX_MAYBE_UNUSED static inline void dxb_sanitize_tail(MDBX_env *env, MDBX_txn *txn) {
|
||||
(void)env;
|
||||
(void)txn;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ typedef struct MDBX_rkl {
|
||||
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL void rkl_init(rkl_t *rkl);
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL void rkl_clear(rkl_t *rkl);
|
||||
static inline void rkl_clear_and_shrink(rkl_t *rkl) { rkl_clear(rkl); /* TODO */ }
|
||||
MDBX_MAYBE_UNUSED static inline void rkl_clear_and_shrink(rkl_t *rkl) { rkl_clear(rkl); /* TODO */ }
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL void rkl_destroy(rkl_t *rkl);
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL void rkl_destructive_move(rkl_t *src, rkl_t *dst);
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL __must_check_result int rkl_copy(const rkl_t *src, rkl_t *dst);
|
||||
|
||||
@@ -25,6 +25,6 @@ MDBX_MAYBE_UNUSED MDBX_INTERNAL void txl_sort(txl_t txl);
|
||||
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL bool txl_contain(const txl_t txl, txnid_t id);
|
||||
|
||||
static inline size_t txl_alloclen(const_txl_t txl) { return txl[-1]; }
|
||||
MDBX_MAYBE_UNUSED static inline size_t txl_alloclen(const_txl_t txl) { return txl[-1]; }
|
||||
|
||||
static inline size_t txl_size(const_txl_t txl) { return txl[0]; }
|
||||
MDBX_MAYBE_UNUSED static inline size_t txl_size(const_txl_t txl) { return txl[0]; }
|
||||
|
||||
@@ -13,12 +13,14 @@ MDBX_NOTHROW_CONST_FUNCTION MDBX_MAYBE_UNUSED static inline size_t field_alignme
|
||||
}
|
||||
|
||||
/* read-thunk for UB-sanitizer */
|
||||
MDBX_NOTHROW_PURE_FUNCTION static inline uint8_t peek_u8(const uint8_t *__restrict ptr) { return *ptr; }
|
||||
MDBX_NOTHROW_PURE_FUNCTION MDBX_MAYBE_UNUSED static inline uint8_t peek_u8(const uint8_t *__restrict ptr) {
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
/* write-thunk for UB-sanitizer */
|
||||
static inline void poke_u8(uint8_t *__restrict ptr, const uint8_t v) { *ptr = v; }
|
||||
MDBX_MAYBE_UNUSED static inline void poke_u8(uint8_t *__restrict ptr, const uint8_t v) { *ptr = v; }
|
||||
|
||||
static inline void *bcopy_2(void *__restrict dst, const void *__restrict src) {
|
||||
MDBX_MAYBE_UNUSED static inline void *bcopy_2(void *__restrict dst, const void *__restrict src) {
|
||||
uint8_t *__restrict d = (uint8_t *)dst;
|
||||
const uint8_t *__restrict s = (uint8_t *)src;
|
||||
d[0] = s[0];
|
||||
@@ -26,7 +28,7 @@ static inline void *bcopy_2(void *__restrict dst, const void *__restrict src) {
|
||||
return d;
|
||||
}
|
||||
|
||||
static inline void *bcopy_4(void *const __restrict dst, const void *const __restrict src) {
|
||||
MDBX_MAYBE_UNUSED static inline void *bcopy_4(void *const __restrict dst, const void *const __restrict src) {
|
||||
uint8_t *__restrict d = (uint8_t *)dst;
|
||||
const uint8_t *__restrict s = (uint8_t *)src;
|
||||
d[0] = s[0];
|
||||
@@ -36,7 +38,7 @@ static inline void *bcopy_4(void *const __restrict dst, const void *const __rest
|
||||
return d;
|
||||
}
|
||||
|
||||
static inline void *bcopy_8(void *const __restrict dst, const void *const __restrict src) {
|
||||
MDBX_MAYBE_UNUSED static inline void *bcopy_8(void *const __restrict dst, const void *const __restrict src) {
|
||||
uint8_t *__restrict d = (uint8_t *)dst;
|
||||
const uint8_t *__restrict s = (uint8_t *)src;
|
||||
d[0] = s[0];
|
||||
@@ -50,8 +52,8 @@ static inline void *bcopy_8(void *const __restrict dst, const void *const __rest
|
||||
return d;
|
||||
}
|
||||
|
||||
MDBX_NOTHROW_PURE_FUNCTION static inline uint16_t unaligned_peek_u16(const size_t expected_alignment,
|
||||
const void *const ptr) {
|
||||
MDBX_NOTHROW_PURE_FUNCTION MDBX_MAYBE_UNUSED static inline uint16_t unaligned_peek_u16(const size_t expected_alignment,
|
||||
const void *const ptr) {
|
||||
assert((uintptr_t)ptr % expected_alignment == 0);
|
||||
if (MDBX_UNALIGNED_OK >= 2 || (expected_alignment % sizeof(uint16_t)) == 0)
|
||||
return *(const uint16_t *)ptr;
|
||||
@@ -66,7 +68,8 @@ MDBX_NOTHROW_PURE_FUNCTION static inline uint16_t unaligned_peek_u16(const size_
|
||||
}
|
||||
}
|
||||
|
||||
static inline void unaligned_poke_u16(const size_t expected_alignment, void *const __restrict ptr, const uint16_t v) {
|
||||
MDBX_MAYBE_UNUSED static inline void unaligned_poke_u16(const size_t expected_alignment, void *const __restrict ptr,
|
||||
const uint16_t v) {
|
||||
assert((uintptr_t)ptr % expected_alignment == 0);
|
||||
if (MDBX_UNALIGNED_OK >= 2 || (expected_alignment % sizeof(v)) == 0)
|
||||
*(uint16_t *)ptr = v;
|
||||
@@ -79,8 +82,8 @@ static inline void unaligned_poke_u16(const size_t expected_alignment, void *con
|
||||
}
|
||||
}
|
||||
|
||||
MDBX_NOTHROW_PURE_FUNCTION static inline uint32_t unaligned_peek_u32(const size_t expected_alignment,
|
||||
const void *const __restrict ptr) {
|
||||
MDBX_NOTHROW_PURE_FUNCTION MDBX_MAYBE_UNUSED static inline uint32_t
|
||||
unaligned_peek_u32(const size_t expected_alignment, const void *const __restrict ptr) {
|
||||
assert((uintptr_t)ptr % expected_alignment == 0);
|
||||
if (MDBX_UNALIGNED_OK >= 4 || (expected_alignment % sizeof(uint32_t)) == 0)
|
||||
return *(const uint32_t *)ptr;
|
||||
@@ -99,7 +102,8 @@ MDBX_NOTHROW_PURE_FUNCTION static inline uint32_t unaligned_peek_u32(const size_
|
||||
}
|
||||
}
|
||||
|
||||
static inline void unaligned_poke_u32(const size_t expected_alignment, void *const __restrict ptr, const uint32_t v) {
|
||||
MDBX_MAYBE_UNUSED static inline void unaligned_poke_u32(const size_t expected_alignment, void *const __restrict ptr,
|
||||
const uint32_t v) {
|
||||
assert((uintptr_t)ptr % expected_alignment == 0);
|
||||
if (MDBX_UNALIGNED_OK >= 4 || (expected_alignment % sizeof(v)) == 0)
|
||||
*(uint32_t *)ptr = v;
|
||||
@@ -115,8 +119,8 @@ static inline void unaligned_poke_u32(const size_t expected_alignment, void *con
|
||||
}
|
||||
}
|
||||
|
||||
MDBX_NOTHROW_PURE_FUNCTION static inline uint64_t unaligned_peek_u64(const size_t expected_alignment,
|
||||
const void *const __restrict ptr) {
|
||||
MDBX_NOTHROW_PURE_FUNCTION MDBX_MAYBE_UNUSED static inline uint64_t
|
||||
unaligned_peek_u64(const size_t expected_alignment, const void *const __restrict ptr) {
|
||||
assert((uintptr_t)ptr % expected_alignment == 0);
|
||||
if (MDBX_UNALIGNED_OK >= 8 || (expected_alignment % sizeof(uint64_t)) == 0)
|
||||
return *(const uint64_t *)ptr;
|
||||
@@ -135,8 +139,8 @@ MDBX_NOTHROW_PURE_FUNCTION static inline uint64_t unaligned_peek_u64(const size_
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint64_t unaligned_peek_u64_volatile(const size_t expected_alignment,
|
||||
const volatile void *const __restrict ptr) {
|
||||
MDBX_MAYBE_UNUSED static inline uint64_t unaligned_peek_u64_volatile(const size_t expected_alignment,
|
||||
const volatile void *const __restrict ptr) {
|
||||
assert((uintptr_t)ptr % expected_alignment == 0);
|
||||
assert(expected_alignment % sizeof(uint32_t) == 0);
|
||||
if (MDBX_UNALIGNED_OK >= 8 || (expected_alignment % sizeof(uint64_t)) == 0)
|
||||
@@ -152,7 +156,8 @@ static inline uint64_t unaligned_peek_u64_volatile(const size_t expected_alignme
|
||||
}
|
||||
}
|
||||
|
||||
static inline void unaligned_poke_u64(const size_t expected_alignment, void *const __restrict ptr, const uint64_t v) {
|
||||
MDBX_MAYBE_UNUSED static inline void unaligned_poke_u64(const size_t expected_alignment, void *const __restrict ptr,
|
||||
const uint64_t v) {
|
||||
assert((uintptr_t)ptr % expected_alignment == 0);
|
||||
if (MDBX_UNALIGNED_OK >= 8 || (expected_alignment % sizeof(v)) == 0)
|
||||
*(uint64_t *)ptr = v;
|
||||
@@ -183,7 +188,7 @@ static inline void unaligned_poke_u64(const size_t expected_alignment, void *con
|
||||
#define UNALIGNED_POKE_64(ptr, struct, field, value) \
|
||||
unaligned_poke_u64(1, ptr_disp(ptr, offsetof(struct, field)), value)
|
||||
|
||||
MDBX_NOTHROW_PURE_FUNCTION static inline pgno_t peek_pgno(const void *const __restrict ptr) {
|
||||
MDBX_NOTHROW_PURE_FUNCTION MDBX_MAYBE_UNUSED static 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);
|
||||
else if (sizeof(pgno_t) == sizeof(uint64_t))
|
||||
@@ -195,7 +200,7 @@ MDBX_NOTHROW_PURE_FUNCTION static inline pgno_t peek_pgno(const void *const __re
|
||||
}
|
||||
}
|
||||
|
||||
static inline void poke_pgno(void *const __restrict ptr, const pgno_t pgno) {
|
||||
MDBX_MAYBE_UNUSED static inline void poke_pgno(void *const __restrict ptr, const pgno_t pgno) {
|
||||
if (sizeof(pgno) == sizeof(uint32_t))
|
||||
unaligned_poke_u32(1, ptr, pgno);
|
||||
else if (sizeof(pgno) == sizeof(uint64_t))
|
||||
|
||||
Reference in New Issue
Block a user