]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
LMDBLS Cleanups
authorFred Morcos <fred.morcos@open-xchange.com>
Thu, 17 Oct 2024 13:42:16 +0000 (15:42 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Thu, 17 Oct 2024 13:45:07 +0000 (15:45 +0200)
ext/lmdb-safe/lmdb-safe.hh

index 7d9bdee4c742280b198ea9e4a90510a5f71e97e1..40f203f21bfd8cea4fb388c17e2454ddaf9bbe21 100644 (file)
@@ -102,46 +102,49 @@ std::shared_ptr<MDBEnv> 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 */