Commit b2e8f49d authored by Kevin Modzelewski's avatar Kevin Modzelewski

Make sure we set tp_dict for pyston classes

We were already doing this for CAPI classes.
Only slightly trickier due to bootstrapping issues.
parent 47d09e58
...@@ -498,6 +498,8 @@ PyAPI_DATA(PyTypeObject*) type_cls; ...@@ -498,6 +498,8 @@ PyAPI_DATA(PyTypeObject*) type_cls;
// Pyston change: this is no longer a static object // Pyston change: this is no longer a static object
//PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */ //PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
//PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */ //PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
PyAPI_DATA(PyTypeObject*) object_cls;
#define PyBaseObject_Type (*object_cls)
// Pyston changes: these aren't direct macros any more [they potentially could be though] // Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC(bool) _PyType_Check(PyObject*) PYSTON_NOEXCEPT; PyAPI_FUNC(bool) _PyType_Check(PyObject*) PYSTON_NOEXCEPT;
......
...@@ -2297,6 +2297,8 @@ void commonClassSetup(BoxedClass* cls) { ...@@ -2297,6 +2297,8 @@ void commonClassSetup(BoxedClass* cls) {
if (PyType_Check(b)) if (PyType_Check(b))
inherit_slots(cls, static_cast<BoxedClass*>(b)); inherit_slots(cls, static_cast<BoxedClass*>(b));
} }
assert(cls->tp_dict && cls->tp_dict->cls == attrwrapper_cls);
} }
extern "C" void PyType_Modified(PyTypeObject* type) noexcept { extern "C" void PyType_Modified(PyTypeObject* type) noexcept {
......
...@@ -383,6 +383,9 @@ void BoxedClass::finishInitialization() { ...@@ -383,6 +383,9 @@ void BoxedClass::finishInitialization() {
tp_clear = tp_base->tp_clear; tp_clear = tp_base->tp_clear;
} }
assert(!this->tp_dict);
this->tp_dict = makeAttrWrapper(this);
commonClassSetup(this); commonClassSetup(this);
} }
......
...@@ -103,7 +103,7 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) ...@@ -103,7 +103,7 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems)
} }
#endif #endif
if (!cls->tp_mro) { if (!cls->tp_mro) {
assert(!list_cls); assert(!attrwrapper_cls); // the last class to be set up during bootstrapping
} else { } else {
assert(cls->tp_mro && "maybe we should just skip these checks if !mro"); assert(cls->tp_mro && "maybe we should just skip these checks if !mro");
assert(cls->tp_mro->cls == tuple_cls); assert(cls->tp_mro->cls == tuple_cls);
...@@ -1455,7 +1455,7 @@ static PyObject* object_reduce_ex(PyObject* self, PyObject* args) noexcept { ...@@ -1455,7 +1455,7 @@ static PyObject* object_reduce_ex(PyObject* self, PyObject* args) noexcept {
Py_DECREF(reduce); Py_DECREF(reduce);
return NULL; return NULL;
} }
objreduce = object_cls->getattr("__reduce__"); objreduce = PyDict_GetItemString(PyBaseObject_Type.tp_dict, "__reduce__");
override = (clsreduce != objreduce); override = (clsreduce != objreduce);
Py_DECREF(clsreduce); Py_DECREF(clsreduce);
if (override) { if (override) {
...@@ -1620,13 +1620,18 @@ void setupRuntime() { ...@@ -1620,13 +1620,18 @@ void setupRuntime() {
EmptyTuple = new BoxedTuple({}); EmptyTuple = new BoxedTuple({});
gc::registerPermanentRoot(EmptyTuple); gc::registerPermanentRoot(EmptyTuple);
list_cls = new BoxedHeapClass(object_cls, &listGCHandler, 0, 0, sizeof(BoxedList), false, boxStrConstant("list")); list_cls = new BoxedHeapClass(object_cls, &listGCHandler, 0, 0, sizeof(BoxedList), false, boxStrConstant("list"));
attrwrapper_cls = new BoxedHeapClass(object_cls, &AttrWrapper::gcHandler, 0, 0, sizeof(AttrWrapper), false,
new BoxedString("attrwrapper"));
// Kind of hacky, but it's easier to manually construct the mro for a couple key classes // Kind of hacky, but it's easier to manually construct the mro for a couple key classes
// than try to make the MRO construction code be safe against say, tuple_cls not having // than try to make the MRO construction code be safe against say, tuple_cls not having
// an mro (since the mro is stored as a tuple). // an mro (since the mro is stored as a tuple).
object_cls->tp_mro = new BoxedTuple({ object_cls });
tuple_cls->tp_mro = new BoxedTuple({ tuple_cls, object_cls }); tuple_cls->tp_mro = new BoxedTuple({ tuple_cls, object_cls });
list_cls->tp_mro = new BoxedTuple({ list_cls, object_cls }); list_cls->tp_mro = new BoxedTuple({ list_cls, object_cls });
type_cls->tp_mro = new BoxedTuple({ type_cls, object_cls }); type_cls->tp_mro = new BoxedTuple({ type_cls, object_cls });
attrwrapper_cls->tp_mro = new BoxedTuple({ attrwrapper_cls, object_cls });
object_cls->finishInitialization(); object_cls->finishInitialization();
type_cls->finishInitialization(); type_cls->finishInitialization();
...@@ -1635,6 +1640,7 @@ void setupRuntime() { ...@@ -1635,6 +1640,7 @@ void setupRuntime() {
none_cls->finishInitialization(); none_cls->finishInitialization();
tuple_cls->finishInitialization(); tuple_cls->finishInitialization();
list_cls->finishInitialization(); list_cls->finishInitialization();
attrwrapper_cls->finishInitialization();
str_cls->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER; str_cls->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER;
...@@ -1689,8 +1695,6 @@ void setupRuntime() { ...@@ -1689,8 +1695,6 @@ void setupRuntime() {
sizeof(BoxedStaticmethod), false, "staticmethod"); sizeof(BoxedStaticmethod), false, "staticmethod");
classmethod_cls = BoxedHeapClass::create(type_cls, object_cls, &classmethodGCHandler, 0, 0, classmethod_cls = BoxedHeapClass::create(type_cls, object_cls, &classmethodGCHandler, 0, 0,
sizeof(BoxedClassmethod), false, "classmethod"); sizeof(BoxedClassmethod), false, "classmethod");
attrwrapper_cls = BoxedHeapClass::create(type_cls, object_cls, &AttrWrapper::gcHandler, 0, 0, sizeof(AttrWrapper),
false, "attrwrapper");
attrwrapperiter_cls = BoxedHeapClass::create(type_cls, object_cls, &AttrWrapperIter::gcHandler, 0, 0, attrwrapperiter_cls = BoxedHeapClass::create(type_cls, object_cls, &AttrWrapperIter::gcHandler, 0, 0,
sizeof(AttrWrapperIter), false, "attrwrapperiter"); sizeof(AttrWrapperIter), false, "attrwrapperiter");
......
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