Browse Source

[2097] introduced the 'next' member; check alignment requirement

JINMEI Tatuya 12 years ago
parent
commit
c097d3c770

+ 4 - 0
src/lib/datasrc/memory/rdataset.cc

@@ -94,6 +94,10 @@ RdataSet::RdataSet(RRType type_param, size_t rdata_count_param,
     // our assumption of the size of RdataSet holds.  If it's not the case
     // we should use the bare value instead of the class object.
     BOOST_STATIC_ASSERT(sizeof(type) == sizeof(uint16_t));
+
+    // Confirm we meet the alignment requirement for RdataEncoder
+    // ("this + 1" should be safely passed to the encoder).
+    BOOST_STATIC_ASSERT(sizeof(RdataSet) % sizeof(uint16_t) == 0);
 }
 
 } // namespace memory

+ 10 - 0
src/lib/datasrc/memory/rdataset.h

@@ -22,6 +22,8 @@
 #include <dns/rrset.h>
 #include <dns/rrttl.h>
 
+#include <boost/interprocess/offset_ptr.hpp>
+
 #include <stdint.h>
 
 namespace isc {
@@ -38,6 +40,14 @@ public:
     static void destroy(util::MemorySegment& mem_sgmt, dns::RRClass rrclass,
                         RdataSet* rdataset);
 
+    typedef boost::interprocess::offset_ptr<RdataSet> RdataSetPtr;
+    typedef boost::interprocess::offset_ptr<const RdataSet> ConstRdataSetPtr;
+
+    // Note: the size and order of the members are important.  Don't change
+    // them unless there's strong reason for that and the consequences are
+    // considered.
+
+    RdataSetPtr next;
     const dns::RRType type;
 private:
     const uint16_t sig_rdata_count : 3;

+ 1 - 0
src/lib/datasrc/memory/tests/rdataset_unittest.cc

@@ -63,6 +63,7 @@ TEST_F(RdataSetTest, create) {
     // would detect any memory leak)
     RdataSet* rdataset = RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
                                           ConstRRsetPtr());
+    EXPECT_FALSE(rdataset->next); // by default the next pointer should be NULL
     EXPECT_EQ(RRType::A(), rdataset->type);
     EXPECT_EQ(RRTTL(1076895760), restoreTTL(rdataset->getTTLData()));
     EXPECT_EQ(1, rdataset->getRdataCount());