Commit 978974b4 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix: free dict+set internal memory

Forgot to do this when I switched away from an StlCompatAllocator,
so we were leaking memory pretty badly.
parent 93ff229e
......@@ -751,6 +751,11 @@ static Box* dict_repr(PyObject* self) noexcept {
}
}
void BoxedDict::dealloc(Box* b) noexcept {
assert(PyDict_Check(b));
static_cast<BoxedDict*>(b)->d.~DictMap();
}
void setupDict() {
dict_iterator_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedDictIterator::gcHandler, 0, 0,
sizeof(BoxedDictIterator), false, "dictionary-itemiterator");
......@@ -762,6 +767,9 @@ void setupDict() {
dict_items_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedDictView::gcHandler, 0, 0,
sizeof(BoxedDictView), false, "dict_items");
dict_cls->tp_dealloc = &BoxedDict::dealloc;
dict_cls->has_safe_tp_dealloc = true;
dict_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)dictLen, BOXED_INT, 1)));
dict_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)dictNew, UNKNOWN, 1, 0, true, true)));
dict_cls->giveAttr("__init__", new BoxedFunction(boxRTFunction((void*)dictInit, NONE, 1, 0, true, true)));
......
......@@ -519,9 +519,17 @@ extern "C" PyObject* PyFrozenSet_New(PyObject* iterable) noexcept {
} // namespace set
void BoxedSet::dealloc(Box* b) noexcept {
assert(PyAnySet_Check(b));
static_cast<BoxedSet*>(b)->s.~Set();
}
using namespace pyston::set;
void setupSet() {
set_cls->tp_dealloc = frozenset_cls->tp_dealloc = BoxedSet::dealloc;
set_cls->has_safe_tp_dealloc = frozenset_cls->has_safe_tp_dealloc = true;
set_iterator_cls = BoxedHeapClass::create(type_cls, object_cls, &BoxedSetIterator::gcHandler, 0, 0,
sizeof(BoxedSetIterator), false, "setiterator");
set_iterator_cls->giveAttr(
......
......@@ -40,6 +40,7 @@ public:
DEFAULT_CLASS(set_cls);
static void gcHandler(GCVisitor* v, Box* b);
static void dealloc(Box* b) noexcept;
};
}
......
......@@ -724,6 +724,7 @@ public:
iterator end() { return iterator(d.end()); }
static void gcHandler(GCVisitor* v, Box* b);
static void dealloc(Box* b) noexcept;
};
static_assert(sizeof(BoxedDict) == sizeof(PyDictObject), "");
......
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