Skip to content

Commit

Permalink
Owners need not be objects WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Borthwick committed Oct 27, 2015
1 parent d778315 commit dcccf37
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion GCPointer/src/GCPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace gc
class gc_ptr_base
{
public:
using OwnerType = Object;
using OwnerType = void;

// TODO: Private
public:
Expand Down
8 changes: 4 additions & 4 deletions GCPointer/src/GCPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ namespace gc
gc_ptr_base& ptr = *it->second;
if (ptr.impl && !ptr.impl->marked)
{
// TODO: Can't assume Object*
Object* pointee = (Object*)ptr.get_void();
nullifyPointersTo(*pointee);
nullifyPointersTo(pointee);

// TODO: Need to prevent this invalidating iterator
delete pointee;
Expand All @@ -91,12 +92,12 @@ namespace gc
}
}

void nullifyPointersTo(OwnerType& pointee)
void nullifyPointersTo(OwnerType* pointee)
{
for (auto entry : pointers)
{
gc_ptr_base& p = *entry.second;
if (p.impl && (p.impl->to == &pointee))
if (p.impl && (p.impl->to == pointee))
{
p.impl = nullptr;
}
Expand All @@ -119,7 +120,6 @@ namespace gc
{
return pointers.equal_range(gc_ptr_base::cNoOwner);
}

};

template<typename T>
Expand Down
24 changes: 24 additions & 0 deletions GCPointer/test/GCPointerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,27 @@ TEST_F(GCPointerTest, vectorAccumulate)

ASSERT_THAT(*joined, Eq("Once upon a time"));
}

TEST_F(GCPointerTest, OwnersNeedNotBeGCObjects)
{
class NotAnObject {
public:
StringPtr value;
gc_ptr<NotAnObject> selfReference;

NotAnObject(string const& value)
: value { make_owned_gc<string>(this, value) }
, selfReference { make_owned_null_gc<NotAnObject>(this) }
{}

virtual ~NotAnObject() {}
};

{
gc_ptr<NotAnObject> p = make_gc<NotAnObject>("Pseudoantidisestablishmentarianism");
p->selfReference = p;
}
collectGarbage();
}

// TODO: Self referencing

0 comments on commit dcccf37

Please sign in to comment.