Commit 31a07ee2 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Sets were horribly broken since they didn't have GC handlers

parent d460425b
...@@ -23,17 +23,19 @@ namespace pyston { ...@@ -23,17 +23,19 @@ namespace pyston {
BoxedClass* set_cls, *set_iterator_cls; BoxedClass* set_cls, *set_iterator_cls;
const ObjectFlavor set_flavor(&boxGCHandler, NULL); extern "C" void setGCHandler(GCVisitor* v, void* p);
const ObjectFlavor set_iterator_flavor(&boxGCHandler, NULL); extern "C" void setIteratorGCHandler(GCVisitor* v, void* p);
const ObjectFlavor set_flavor(&setGCHandler, NULL);
const ObjectFlavor set_iterator_flavor(&setIteratorGCHandler, NULL);
namespace set { namespace set {
class BoxedSetIterator : public Box { class BoxedSetIterator : public Box {
private: public:
BoxedSet* s; BoxedSet* s;
decltype(BoxedSet::s)::iterator it; decltype(BoxedSet::s)::iterator it;
public:
BoxedSetIterator(BoxedSet* s) : Box(&set_iterator_flavor, set_iterator_cls), s(s), it(s->s.begin()) {} BoxedSetIterator(BoxedSet* s) : Box(&set_iterator_flavor, set_iterator_cls), s(s), it(s->s.begin()) {}
bool hasNext() { return it != s->s.end(); } bool hasNext() { return it != s->s.end(); }
...@@ -45,6 +47,29 @@ public: ...@@ -45,6 +47,29 @@ public:
} }
}; };
extern "C" void setGCHandler(GCVisitor* v, void* p) {
boxGCHandler(v, p);
BoxedSet* s = (BoxedSet*)p;
// This feels like a cludge, but we need to find anything that
// the unordered_map might have allocated.
// Another way to handle this would be to rt_alloc the unordered_map
// as well, though that incurs extra memory dereferences which would
// be nice to avoid.
void** start = (void**)&s->s;
void** end = start + (sizeof(s->s) / 8);
v->visitPotentialRange(start, end);
}
extern "C" void setIteratorGCHandler(GCVisitor* v, void* p) {
boxGCHandler(v, p);
BoxedSetIterator* it = (BoxedSetIterator*)p;
v->visit(it->s);
}
Box* setiteratorHasnext(BoxedSetIterator* self) { Box* setiteratorHasnext(BoxedSetIterator* self) {
assert(self->cls == set_iterator_cls); assert(self->cls == set_iterator_cls);
return boxBool(self->hasNext()); return boxBool(self->hasNext());
......
...@@ -26,3 +26,5 @@ s.add("") ...@@ -26,3 +26,5 @@ s.add("")
print len(s) print len(s)
s.add(None) s.add(None)
print len(s) print len(s)
print set([1])
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