Commit 13b16c09 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2105] Pass memory segment to operator() of the deleter class

parent 0ea32d79
......@@ -248,16 +248,18 @@ public:
/// \brief Set the data stored in the node. If there is old data, it
/// is either returned or destroyed based on what is passed in \c
/// old_data.
/// \param mem_sgmt The \c MemorySegment that allocated memory for
/// the node data.
/// \param data The new data to set.
/// \param old_data If \c NULL is passed here, any old data is
/// destroyed. Otherwise, the old data is returned
/// in this location.
void setData(T* data, T** old_data = NULL) {
void setData(util::MemorySegment& mem_sgmt, T* data, T** old_data = NULL) {
if (old_data != NULL) {
*old_data = data;
} else {
const DT deleter;
deleter(data_);
deleter(mem_sgmt, data_);
}
data_ = data;
}
......@@ -876,7 +878,7 @@ public:
/// \param mem_sgmt A \c MemorySegment from which memory for the new
/// \c DomainTree is allocated.
static DomainTree* create(util::MemorySegment& mem_sgmt,
bool return_empty_node = false)
bool return_empty_node = false)
{
void* p = mem_sgmt.allocate(sizeof(DomainTree<T, DT>));
return (new(p) DomainTree<T, DT>(return_empty_node));
......@@ -1389,14 +1391,14 @@ DomainTree<T, DT>::deleteHelper(util::MemorySegment& mem_sgmt,
}
deleteHelper(mem_sgmt, node->getDown(), deleter);
deleter(node->data_);
deleter(mem_sgmt, node->data_);
DomainTreeNode<T, DT>::destroy(mem_sgmt, node);
--node_count_;
node = parent;
}
deleteHelper(mem_sgmt, root->getDown(), deleter);
deleter(root->data_);
deleter(mem_sgmt, root->data_);
DomainTreeNode<T, DT>::destroy(mem_sgmt, root);
--node_count_;
}
......
......@@ -63,7 +63,7 @@ class DeleterType {
public:
DeleterType() {}
void operator()(int* i) const {
void operator()(util::MemorySegment&, int* i) const {
delete i;
}
};
......@@ -102,11 +102,11 @@ protected:
int name_count = sizeof(domain_names) / sizeof(domain_names[0]);
for (int i = 0; i < name_count; ++i) {
dtree.insert(mem_sgmt_, Name(domain_names[i]), &dtnode);
dtnode->setData(new int(i + 1));
dtnode->setData(mem_sgmt_, new int(i + 1));
dtree_expose_empty_node.insert(mem_sgmt_, Name(domain_names[i]),
&dtnode);
dtnode->setData(new int(i + 1));
dtnode->setData(mem_sgmt_, new int(i + 1));
}
}
......@@ -130,7 +130,7 @@ TEST_F(DomainTreeTest, nodeCount) {
}
TEST_F(DomainTreeTest, setGetData) {
dtnode->setData(new int(11));
dtnode->setData(mem_sgmt_, new int(11));
EXPECT_EQ(11, *(dtnode->getData()));
}
......@@ -151,7 +151,7 @@ TEST_F(DomainTreeTest, insertNames) {
Name("example.com"),
&dtnode));
EXPECT_EQ(17, dtree.getNodeCount());
dtnode->setData(new int(12));
dtnode->setData(mem_sgmt_, new int(12));
// return ALREADYEXISTS, since node "example.com" already has
// been explicitly inserted
......@@ -381,7 +381,7 @@ performCallbackTest(TestDomainTree& dtree,
EXPECT_EQ(TestDomainTree::SUCCESS, dtree.insert(mem_sgmt,
Name("callback.example"),
&dtnode));
dtnode->setData(new int(1));
dtnode->setData(mem_sgmt, new int(1));
EXPECT_FALSE(dtnode->getFlag(TestDomainTreeNode::FLAG_CALLBACK));
// enable/re-disable callback
......@@ -397,7 +397,7 @@ performCallbackTest(TestDomainTree& dtree,
EXPECT_EQ(TestDomainTree::SUCCESS, dtree.insert(mem_sgmt,
Name("sub.callback.example"),
&subdtnode));
subdtnode->setData(new int(2));
subdtnode->setData(mem_sgmt, new int(2));
TestDomainTreeNode* parentdtnode;
EXPECT_EQ(TestDomainTree::ALREADYEXISTS, dtree.insert(mem_sgmt,
Name("example"),
......@@ -997,7 +997,7 @@ TEST_F(DomainTreeTest, root) {
TreeHolder tree_holder(mem_sgmt_, TestDomainTree::create(mem_sgmt_));
TestDomainTree& root(*tree_holder.get());
root.insert(mem_sgmt_, Name::ROOT_NAME(), &dtnode);
dtnode->setData(new int(1));
dtnode->setData(mem_sgmt_, new int(1));
EXPECT_EQ(TestDomainTree::EXACTMATCH,
root.find(Name::ROOT_NAME(), &cdtnode));
......@@ -1009,7 +1009,7 @@ TEST_F(DomainTreeTest, root) {
// Insert a new name that better matches the query name. find() should
// find the better one.
root.insert(mem_sgmt_, Name("com"), &dtnode);
dtnode->setData(new int(2));
dtnode->setData(mem_sgmt_, new int(2));
EXPECT_EQ(TestDomainTree::PARTIALMATCH,
root.find(Name("example.com"), &cdtnode));
EXPECT_EQ(dtnode, cdtnode);
......
Markdown is supported
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