Commit 89a67792 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2420] refactoring: reorder RdataSet::destroy to meet segment obj holder req.

not directly related to the subject of this branch, but this will help
the development.
parent c8b32f1a
......@@ -122,8 +122,8 @@ RdataSet::create(util::MemorySegment& mem_sgmt, RdataEncoder& encoder,
}
void
RdataSet::destroy(util::MemorySegment& mem_sgmt, RRClass rrclass,
RdataSet* rdataset)
RdataSet::destroy(util::MemorySegment& mem_sgmt, RdataSet* rdataset,
RRClass rrclass)
{
const size_t data_len =
RdataReader(rrclass, rdataset->type,
......
......@@ -187,12 +187,12 @@ public:
///
/// \param mem_sgmt The \c MemorySegment that allocated memory for
/// \c node.
/// \param rrclass The RR class of the \c RdataSet to be destroyed.
/// \param rdataset A non NULL pointer to a valid \c RdataSet object
/// \param rrclass The RR class of the \c RdataSet to be destroyed.
/// that was originally created by the \c create() method (the behavior
/// is undefined if this condition isn't met).
static void destroy(util::MemorySegment& mem_sgmt, dns::RRClass rrclass,
RdataSet* rdataset);
static void destroy(util::MemorySegment& mem_sgmt, RdataSet* rdataset,
dns::RRClass rrclass);
/// \brief Find \c RdataSet of given RR type from a list (const version).
///
......
......@@ -49,7 +49,7 @@ rdataSetDeleter(RRClass rrclass, util::MemorySegment* mem_sgmt,
rdataset = rdataset_next)
{
rdataset_next = rdataset->getNext();
RdataSet::destroy(*mem_sgmt, rrclass, rdataset);
RdataSet::destroy(*mem_sgmt, rdataset, rrclass);
}
}
......
......@@ -253,7 +253,7 @@ ZoneDataUpdater::addNSEC3(const ConstRRsetPtr rrset, const ConstRRsetPtr rrsig)
RdataSet* rdataset = RdataSet::create(mem_sgmt_, encoder_, rrset, rrsig);
RdataSet* old_rdataset = node->setData(rdataset);
if (old_rdataset != NULL) {
RdataSet::destroy(mem_sgmt_, rrclass_, old_rdataset);
RdataSet::destroy(mem_sgmt_, old_rdataset, rrclass_);
}
}
......
......@@ -24,6 +24,7 @@
#include <dns/rrtype.h>
#include <dns/rrttl.h>
#include <datasrc/memory/segment_object_holder.h>
#include <datasrc/memory/rdata_serialization.h>
#include <datasrc/memory/rdataset.h>
......@@ -112,7 +113,7 @@ TEST_F(RdataSetTest, create) {
RdataSet* rdataset = RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
ConstRRsetPtr());
checkRdataSet(*rdataset, true, false);
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
}
TEST_F(RdataSetTest, getNext) {
......@@ -131,7 +132,7 @@ TEST_F(RdataSetTest, getNext) {
rdataset->next = rdataset;
EXPECT_EQ(rdataset, static_cast<const RdataSet*>(rdataset)->getNext());
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
}
// A helper function to create an RRset containing the given number of
......@@ -154,7 +155,7 @@ TEST_F(RdataSetTest, createManyRRs) {
ConstRRsetPtr());
EXPECT_EQ(8191, rdataset->getRdataCount());
EXPECT_EQ(0, rdataset->getSigRdataCount());
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
// Exceeding that will result in an exception.
EXPECT_THROW(RdataSet::create(mem_sgmt_, encoder_,
......@@ -173,7 +174,7 @@ TEST_F(RdataSetTest, createWithRRSIG) {
RdataSet* rdataset = RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
rrsig_rrset_);
checkRdataSet(*rdataset, true, true);
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
// Unusual case: TTL doesn't match. This implementation accepts that,
// using the TTL of the covered RRset.
......@@ -183,7 +184,7 @@ TEST_F(RdataSetTest, createWithRRSIG) {
"20120715220826 1234 example.com. FAKE"));
rdataset = RdataSet::create(mem_sgmt_, encoder_, a_rrset_, rrsig_badttl);
checkRdataSet(*rdataset, true, true);
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
}
// A helper function to create an RRSIG RRset containing the given number of
......@@ -218,21 +219,21 @@ TEST_F(RdataSetTest, createManyRRSIGs) {
RdataSet* rdataset = RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
getRRSIGWithRdataCount(7));
EXPECT_EQ(7, rdataset->getSigRdataCount());
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
// 8 would cause overflow in the normal 3-bit field if there were no extra
// count field.
rdataset = RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
getRRSIGWithRdataCount(8));
EXPECT_EQ(8, rdataset->getSigRdataCount());
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
// Up to 2^16-1 RRSIGs are allowed (although that would be useless
// in practice)
rdataset = RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
getRRSIGWithRdataCount(65535));
EXPECT_EQ(65535, rdataset->getSigRdataCount());
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
// Exceeding this limit will result in an exception.
EXPECT_THROW(RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
......@@ -250,7 +251,7 @@ TEST_F(RdataSetTest, createWithRRSIGOnly) {
RdataSet* rdataset = RdataSet::create(mem_sgmt_, encoder_, ConstRRsetPtr(),
rrsig_rrset_);
checkRdataSet(*rdataset, false, true);
RdataSet::destroy(mem_sgmt_, RRClass::IN(), rdataset);
RdataSet::destroy(mem_sgmt_, rdataset, RRClass::IN());
}
TEST_F(RdataSetTest, badCeate) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment