From: Fred Morcos Date: Thu, 17 Oct 2024 13:42:16 +0000 (+0200) Subject: LMDBLS Cleanups X-Git-Tag: rec-5.2.0-alpha1~23^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=235c0416f9083a54c7fa16c62b8846165520a68e;p=thirdparty%2Fpdns.git LMDBLS Cleanups --- diff --git a/ext/lmdb-safe/lmdb-safe.hh b/ext/lmdb-safe/lmdb-safe.hh index 7d9bdee4c7..40f203f21b 100644 --- a/ext/lmdb-safe/lmdb-safe.hh +++ b/ext/lmdb-safe/lmdb-safe.hh @@ -102,46 +102,49 @@ std::shared_ptr getMDBEnv(const char* fname, int flags, int mode, uint64 #ifndef DNSDIST +struct MDBOutVal; // forward declaration because of how the functions below tie in with MDBOutVal + +namespace LMDBLS { + class __attribute__((__packed__)) LSheader { + private: + static auto bswap64(uint64_t value) -> uint64_t + { #if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__) || !defined(__ORDER_BIG_ENDIAN__) -#error "your compiler did not define byte order macros" +#error "your compiler does not define byte order macros" #endif -// FIXME do something more portable than __builtin_bswap64 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#define _LMDB_SAFE_BSWAP64MAYBE(x) __builtin_bswap64(x) + // FIXME: Do something more portable than __builtin_bswap64. + return __builtin_bswap64(value); #else -#define _LMDB_SAFE_BSWAP64MAYBE(x) (x) + return value; #endif + } -struct MDBOutVal; // forward declaration because of how the functions below tie in with MDBOutVal - -namespace LMDBLS { - class __attribute__((__packed__)) LSheader { public: uint64_t d_timestamp; uint64_t d_txnid; uint8_t d_version; uint8_t d_flags; - uint32_t d_reserved; + uint32_t d_reserved{}; uint16_t d_numextra; - LSheader(uint64_t timestamp, uint64_t txnid, uint8_t flags=0, uint8_t version=0, uint8_t numextra=0): - d_timestamp(_LMDB_SAFE_BSWAP64MAYBE(timestamp)), - d_txnid(_LMDB_SAFE_BSWAP64MAYBE(txnid)), + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) + LSheader(uint64_t timestamp, uint64_t txnid, uint8_t flags = 0, uint8_t version = 0, uint8_t numextra = 0) : + d_timestamp(bswap64(timestamp)), + d_txnid(bswap64(txnid)), d_version(version), d_flags(flags), - d_reserved(0), d_numextra(htons(numextra)) { - } std::string toString() { return std::string((char*)this, sizeof(*this)) + std::string(ntohs(d_numextra)*8, '\0'); } - uint64_t getTimestamp() const { - return _LMDB_SAFE_BSWAP64MAYBE(d_timestamp); + [[nodiscard]] uint64_t getTimestamp() const { + return bswap64(d_timestamp); } }; @@ -161,8 +164,6 @@ namespace LMDBLS { extern bool s_flag_deleted; } -#undef _LMDB_SAFE_BSWAP64MAYBE - #endif /* ifndef DNSDIST */