Commit 0b3ebad3 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Ok, gc is clearing most things now

parent 437a1468
......@@ -119,6 +119,8 @@ PyAPI_FUNC(void) PyType_GiveHcAttrsDictDescr(PyTypeObject*) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject*) PyObject_GetHcAttrString(PyObject*, const char*) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyObject_SetHcAttrString(PyObject*, const char*, PyObject*) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyObject_DelHcAttrString(PyObject*, const char*) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyObject_ClearHcAttrs(PyHcAttrs*) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyObject_TraverseHcAttrs(PyHcAttrs*, visitproc visit, void* arg) PYSTON_NOEXCEPT;
// Workaround: call this instead of setting tp_dict.
PyAPI_FUNC(void) PyType_SetDict(PyTypeObject*, PyObject*) PYSTON_NOEXCEPT;
......@@ -128,6 +130,10 @@ PyAPI_FUNC(void) PyType_SetDict(PyTypeObject*, PyObject*) PYSTON_NOEXCEPT;
// PyType_Ready calls this automatically.
PyAPI_FUNC(void) PyGC_RegisterStaticConstant(PyObject*) PYSTON_NOEXCEPT;
// Pyston addition:
PyAPI_FUNC(void) PyGC_Enable() PYSTON_NOEXCEPT;
PyAPI_FUNC(void) PyGC_Disable() PYSTON_NOEXCEPT;
#include "codecs.h"
#include "pyerrors.h"
......
......@@ -117,6 +117,7 @@ BaseException_clear(PyBaseExceptionObject *self)
{
// Pyston change:
// Py_CLEAR(self->dict);
PyObject_ClearHcAttrs(&self->hcattrs);
Py_CLEAR(self->args);
Py_CLEAR(self->message);
return 0;
......@@ -135,6 +136,9 @@ BaseException_traverse(PyBaseExceptionObject *self, visitproc visit, void *arg)
{
// Pyston change:
// Py_VISIT(self->dict);
int vret = PyObject_TraverseHcAttrs(&self->hcattrs, visit, arg);
if (vret)
return vret;
Py_VISIT(self->args);
Py_VISIT(self->message);
return 0;
......
......@@ -592,6 +592,7 @@ public:
HCAttrs(HiddenClass* hcls = root_hcls) : hcls(hcls), attr_list(nullptr) {}
int traverse(visitproc visit, void* arg) noexcept;
void clear() noexcept;
};
static_assert(sizeof(HCAttrs) == sizeof(struct _hcattrs), "");
......
......@@ -3085,10 +3085,12 @@ extern "C" void PyObject_InitHcAttrs(HCAttrs* attrs) noexcept {
extern "C" PyObject* PyObject_GetHcAttrString(PyObject* obj, const char* attr) PYSTON_NOEXCEPT {
return obj->getattr(internStringMortal(attr));
}
extern "C" int PyObject_SetHcAttrString(PyObject* obj, const char* attr, PyObject* val) PYSTON_NOEXCEPT {
obj->setattr(internStringMortal(attr), val, NULL);
return 0;
}
extern "C" int PyObject_DelHcAttrString(PyObject* obj, const char* attr) PYSTON_NOEXCEPT {
BoxedString* attr_str = internStringMortal(attr);
bool has = obj->hasattr(attr_str);
......@@ -3098,6 +3100,15 @@ extern "C" int PyObject_DelHcAttrString(PyObject* obj, const char* attr) PYSTON_
return 0;
}
extern "C" int PyObject_ClearHcAttrs(HCAttrs* attrs) noexcept {
attrs->clear();
return 0;
}
extern "C" int PyObject_TraverseHcAttrs(HCAttrs* attrs, visitproc visit, void* arg) noexcept {
return attrs->traverse(visit, arg);
}
extern "C" PyVarObject* PyObject_InitVar(PyVarObject* op, PyTypeObject* tp, Py_ssize_t size) noexcept {
assert(op);
assert(tp);
......@@ -3320,20 +3331,7 @@ static Box* getsetDelete(Box* self, Box* obj) {
void Box::clearAttrs() {
if (cls->instancesHaveHCAttrs()) {
HCAttrs* attrs = getHCAttrsPtr();
HiddenClass* hcls = attrs->hcls;
if (unlikely(hcls->type == HiddenClass::DICT_BACKED)) {
Box* d = attrs->attr_list->attrs[0];
Py_DECREF(d);
return;
}
assert(hcls->type == HiddenClass::NORMAL || hcls->type == HiddenClass::SINGLETON);
for (int i = 0; i < hcls->attributeArraySize(); i++) {
Py_DECREF(attrs->attr_list->attrs[i]);
}
new ((void*)attrs) HCAttrs(root_hcls);
attrs->clear();
return;
}
......@@ -3344,6 +3342,23 @@ void Box::clearAttrs() {
}
}
void HCAttrs::clear() noexcept {
HiddenClass* hcls = this->hcls;
if (unlikely(hcls->type == HiddenClass::DICT_BACKED)) {
Box* d = this->attr_list->attrs[0];
Py_DECREF(d);
return;
}
assert(hcls->type == HiddenClass::NORMAL || hcls->type == HiddenClass::SINGLETON);
for (int i = 0; i < hcls->attributeArraySize(); i++) {
Py_DECREF(this->attr_list->attrs[i]);
}
new ((void*)this) HCAttrs(root_hcls);
}
static void tupledealloc(PyTupleObject* op) noexcept {
Py_ssize_t i;
Py_ssize_t len = Py_SIZE(op);
......@@ -4127,7 +4142,9 @@ void setupRuntime() {
for (auto b : classes) {
Py_DECREF(b);
}
PyGC_Collect();
// May need to run multiple collections to collect everything:
while (PyGC_Collect())
;
PRINT_TOTAL_REFS();
exit(0);
// XXX
......
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