Commit b6df2364 authored by Kevin Modzelewski's avatar Kevin Modzelewski

working through pytype_ready

parent ead008eb
...@@ -3408,6 +3408,8 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept { ...@@ -3408,6 +3408,8 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
ASSERT(!cls->is_pyston_class, "should not call this on Pyston classes"); ASSERT(!cls->is_pyston_class, "should not call this on Pyston classes");
gc::registerNonheapRootObject(cls, sizeof(PyTypeObject)); gc::registerNonheapRootObject(cls, sizeof(PyTypeObject));
classes.push_back(cls);
_Py_INC_REFTOTAL;
// unhandled fields: // unhandled fields:
int ALLOWABLE_FLAGS = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES int ALLOWABLE_FLAGS = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES
...@@ -3440,7 +3442,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept { ...@@ -3440,7 +3442,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
base = cls->tp_base = object_cls; base = cls->tp_base = object_cls;
if (!cls->cls) if (!cls->cls)
cls->cls = cls->tp_base->cls; cls->cls = cls->tp_base->cls;
cls->giveAttr("__base__", base); cls->giveAttrBorrowed("__base__", base);
assert(cls->tp_dict == NULL); assert(cls->tp_dict == NULL);
cls->tp_dict = cls->getAttrWrapper(); cls->tp_dict = cls->getAttrWrapper();
......
...@@ -3678,6 +3678,15 @@ void BoxedModule::dealloc(Box* b) noexcept { ...@@ -3678,6 +3678,15 @@ void BoxedModule::dealloc(Box* b) noexcept {
self->clearAttrs(); self->clearAttrs();
} }
void BoxedClass::dealloc(Box* b) noexcept {
BoxedClass* self = static_cast<BoxedClass*>(b);
self->clearAttrs();
Py_XDECREF(self->tp_dict);
// XXX: need to import cpython's type_dealloc
}
#ifndef Py_REF_DEBUG #ifndef Py_REF_DEBUG
#define PRINT_TOTAL_REFS() #define PRINT_TOTAL_REFS()
...@@ -3707,6 +3716,7 @@ void setupRuntime() { ...@@ -3707,6 +3716,7 @@ void setupRuntime() {
type_cls->has_safe_tp_dealloc = false; type_cls->has_safe_tp_dealloc = false;
type_cls->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS; type_cls->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS;
type_cls->tp_itemsize = sizeof(BoxedHeapClass::SlotOffset); type_cls->tp_itemsize = sizeof(BoxedHeapClass::SlotOffset);
type_cls->tp_dealloc = BoxedClass::dealloc;
PyObject_Init(object_cls, type_cls); PyObject_Init(object_cls, type_cls);
PyObject_Init(type_cls, type_cls); PyObject_Init(type_cls, type_cls);
// XXX silly that we have to set this again // XXX silly that we have to set this again
......
...@@ -293,6 +293,8 @@ public: ...@@ -293,6 +293,8 @@ public:
DEFAULT_CLASS_VAR(type_cls, sizeof(SlotOffset)); DEFAULT_CLASS_VAR(type_cls, sizeof(SlotOffset));
static void dealloc(Box* self) noexcept;
protected: protected:
// These functions are not meant for external callers and will mostly just be called // These functions are not meant for external callers and will mostly just be called
// by BoxedHeapClass::create(), but setupRuntime() also needs to do some manual class // by BoxedHeapClass::create(), but setupRuntime() also needs to do some manual class
......
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