mirror of
https://github.com/isar/libmdbx.git
synced 2025-12-19 06:02:21 +08:00
mdbx++: using internal structures in the C++ portion of library.
This commit is contained in:
@@ -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