Skip to content

Commit

Permalink
Fix new[] usage in treetest to refer that defined in class gc
Browse files Browse the repository at this point in the history
(fix of commit 9e27ff8, d6600fe)

Now, both `new[]` and `delete[]` operators invoked in `tree.cc` refer
to that of class `gc`, not to the global definition.

* tests/tree.cc (PTree): Define as a class (derived from class `gc`)
with `ptr` field.
* tests/tree.cc (Tree::Tree, Tree::~Tree, Tree::verify): Change
`m_nodes[i]` to `m_nodes[i].ptr`.
* tests/tree.cc [GC_OPERATOR_NEW_ARRAY] (Tree::~Tree): Replace
`GC_NS_QUALIFY(gc)::operator delete[]()` to `delete[]`.
  • Loading branch information
ivmai committed Dec 9, 2024
1 parent d6600fe commit 8123aa1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
#define USE_GC GC_NS_QUALIFY(UseGC)

class Tree;
typedef Tree *PTree;

class PTree : public GC_NS_QUALIFY(gc)
{
public:
Tree *ptr;
};

class Tree : public GC_NS_QUALIFY(gc)
{
Expand Down Expand Up @@ -47,7 +52,8 @@ Tree::Tree(int a, int d) : arity(a), depth(d)
GC_OP_NEW_OOM_CHECK(nodes);
#endif
for (int i = 0; i < arity; i++) {
GC_PTR_STORE_AND_DIRTY(&nodes[i], new (USE_GC) Tree(arity, depth - 1));
GC_PTR_STORE_AND_DIRTY(&nodes[i].ptr,
new (USE_GC) Tree(arity, depth - 1));
}
}
this->m_nodes = nodes;
Expand All @@ -59,10 +65,10 @@ Tree::~Tree()
{
if (depth > 0) {
for (int i = 0; i < arity; i++) {
delete m_nodes[i];
delete m_nodes[i].ptr;
}
#ifdef GC_OPERATOR_NEW_ARRAY
GC_NS_QUALIFY(gc)::operator delete[](m_nodes);
delete[] m_nodes;
#else
GC_FREE(m_nodes);
#endif
Expand Down Expand Up @@ -101,7 +107,7 @@ Tree::verify(int a, int d)
if (0 == depth)
return;
for (int i = 0; i < arity; i++) {
m_nodes[i]->verify(a, d - 1);
m_nodes[i].ptr->verify(a, d - 1);
}
}

Expand Down

0 comments on commit 8123aa1

Please sign in to comment.