Commit f2c88c16 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get farther with the gc: don't need to clear constant's attrs

parent 0b3ebad3
......@@ -200,7 +200,11 @@ extern "C" void PyDict_Clear(PyObject* op) noexcept {
}
RELEASE_ASSERT(PyDict_Check(op), "");
static_cast<BoxedDict*>(op)->d.clear();
for (auto p : *static_cast<BoxedDict*>(op)) {
Py_DECREF(p.first);
Py_DECREF(p.second);
}
static_cast<BoxedDict*>(op)->d.freeAllMemory();
}
extern "C" PyObject* PyDict_Copy(PyObject* o) noexcept {
......@@ -764,11 +768,8 @@ void BoxedDict::dealloc(Box* b) noexcept {
_PyObject_GC_UNTRACK(b);
assert(PyDict_Check(b));
for (auto p : *static_cast<BoxedDict*>(b)) {
Py_DECREF(p.first);
Py_DECREF(p.second);
}
static_cast<BoxedDict*>(b)->d.freeAllMemory();
BoxedDict::clear(b);
b->cls->tp_free(b);
}
......
......@@ -3393,11 +3393,33 @@ tupletraverse(PyTupleObject *o, visitproc visit, void *arg)
void BoxedModule::dealloc(Box* b) noexcept {
BoxedModule* self = static_cast<BoxedModule*>(b);
self->clearAttrs();
BoxedModule::clear(b);
b->cls->tp_free(b);
}
int BoxedModule::traverse(Box* _m, visitproc visit, void* arg) noexcept {
BoxedModule* m = static_cast<BoxedModule*>(_m);
Py_VISIT_HCATTRS(m->attrs);
return 0;
}
int BoxedModule::clear(Box* b) noexcept {
BoxedModule* self = static_cast<BoxedModule*>(b);
self->clearAttrs();
assert(!self->str_constants.size());
assert(!self->unicode_constants.size());
assert(!self->int_constants.size());
assert(!self->float_constants.size());
assert(!self->imaginary_constants.size());
assert(!self->long_constants.size());
assert(!self->keep_alive.size());
return 0;
}
void BoxedSlice::dealloc(Box* b) noexcept {
BoxedSlice* self = static_cast<BoxedSlice*>(b);
......@@ -3408,12 +3430,6 @@ void BoxedSlice::dealloc(Box* b) noexcept {
PyObject_Del(b);
}
int BoxedModule::traverse(Box* _m, visitproc visit, void* arg) noexcept {
BoxedModule* m = static_cast<BoxedModule*>(_m);
Py_VISIT_HCATTRS(m->attrs);
return 0;
}
void BoxedInstanceMethod::dealloc(Box* b) noexcept {
BoxedInstanceMethod* im = static_cast<BoxedInstanceMethod*>(b);
......@@ -3727,7 +3743,7 @@ void setupRuntime() {
function_cls->has_safe_tp_dealloc = builtin_function_or_method_cls->has_safe_tp_dealloc = true;
module_cls = new (0) BoxedClass(object_cls, offsetof(BoxedModule, attrs), 0, sizeof(BoxedModule), false, "module",
BoxedModule::dealloc, NULL, true, BoxedModule::traverse, NOCLEAR);
BoxedModule::dealloc, NULL, true, BoxedModule::traverse, BoxedModule::clear);
member_descriptor_cls = new (0)
BoxedClass(object_cls, 0, 0, sizeof(BoxedMemberDescriptor), false, "member_descriptor", NULL, NULL, false);
capifunc_cls = new (0)
......@@ -4136,7 +4152,6 @@ void setupRuntime() {
}
}
for (auto b : constants) {
b->clearAttrs();
Py_DECREF(b);
}
for (auto b : classes) {
......
......@@ -905,6 +905,7 @@ public:
static void dealloc(Box* b) noexcept;
static int traverse(Box* self, visitproc visit, void *arg) noexcept;
static int clear(Box* b) noexcept;
private:
ContiguousMap<llvm::StringRef, BoxedString*, llvm::StringMap<int>> str_constants;
......
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