Commit e5a0e465 authored by Kevin Modzelewski's avatar Kevin Modzelewski

A couple fixes and things seem to be working ok

parent 39dbe4fd
......@@ -1536,6 +1536,23 @@ static void inherit_slots(PyTypeObject* type, PyTypeObject* base) {
}
}
// PystonType_Ready is for the common code between PyType_Ready (which is just for extension classes)
// and our internal type-creation endpoints (BoxedClass::BoxedClass()).
// TODO: Move more of the duplicated logic into here.
void PystonType_Ready(BoxedClass* cls) {
inherit_special(cls, cls->tp_base);
// This is supposed to be over the MRO but we don't support multiple inheritance yet:
BoxedClass* b = cls->tp_base;
while (b) {
// Not sure when this could fail; maybe not in Pyston right now but apparently it can in CPython:
if (PyType_Check(b))
inherit_slots(cls, b);
b = b->tp_base;
}
}
extern "C" int PyType_Ready(PyTypeObject* cls) {
gc::registerNonheapRootObject(cls);
......@@ -1642,17 +1659,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) {
printf("warning: ignoring tp_getset for now\n");
}
inherit_special(cls, cls->tp_base);
// This is supposed to be over the MRO but we don't support multiple inheritance yet:
BoxedClass* b = base;
while (b) {
// Not sure when this could fail; maybe not in Pyston right now but apparently it can in CPython:
if (PyType_Check(b))
inherit_slots(cls, b);
b = b->tp_base;
}
PystonType_Ready(cls);
cls->gc_visit = &conservativeGCHandler;
cls->is_user_defined = true;
......
......@@ -23,6 +23,7 @@ namespace pyston {
bool update_slot(BoxedClass* self, const std::string& attr);
void fixup_slot_dispatchers(BoxedClass* self);
void PystonType_Ready(BoxedClass* cls);
}
#endif
......@@ -801,7 +801,8 @@ extern "C" int PyExceptionInstance_Check(PyObject* o) {
}
extern "C" const char* PyExceptionClass_Name(PyObject* o) {
return PyClass_Check(o) ? PyString_AS_STRING(static_cast<BoxedClassobj*>(o)->name) : o->cls->tp_name;
return PyClass_Check(o) ? PyString_AS_STRING(static_cast<BoxedClassobj*>(o)->name)
: static_cast<BoxedClass*>(o)->tp_name;
}
extern "C" PyObject* PyExceptionInstance_Class(PyObject* o) {
......
......@@ -3334,6 +3334,8 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
// TODO should this function (typeNew) call PyType_Ready?
made->tp_new = base->tp_new;
made->tp_alloc = reinterpret_cast<decltype(cls->tp_alloc)>(PyType_GenericAlloc);
PystonType_Ready(made);
fixup_slot_dispatchers(made);
return made;
......
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