Commit f250404f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add tp_alloc test and fix the inheritance issues it exposed

parent 8f8ed3f5
...@@ -1599,7 +1599,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept { ...@@ -1599,7 +1599,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
RELEASE_ASSERT(cls->tp_iternext == NULL, ""); RELEASE_ASSERT(cls->tp_iternext == NULL, "");
RELEASE_ASSERT(cls->tp_descr_get == NULL, ""); RELEASE_ASSERT(cls->tp_descr_get == NULL, "");
RELEASE_ASSERT(cls->tp_descr_set == NULL, ""); RELEASE_ASSERT(cls->tp_descr_set == NULL, "");
RELEASE_ASSERT(cls->tp_alloc == NULL || cls->tp_alloc == PyType_GenericAlloc, "");
RELEASE_ASSERT(cls->tp_free == NULL || cls->tp_free == PyObject_Del, ""); RELEASE_ASSERT(cls->tp_free == NULL || cls->tp_free == PyObject_Del, "");
RELEASE_ASSERT(cls->tp_is_gc == NULL, ""); RELEASE_ASSERT(cls->tp_is_gc == NULL, "");
RELEASE_ASSERT(cls->tp_mro == NULL, ""); RELEASE_ASSERT(cls->tp_mro == NULL, "");
...@@ -1637,10 +1636,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept { ...@@ -1637,10 +1636,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
if (!cls->tp_new && base != object_cls) if (!cls->tp_new && base != object_cls)
cls->tp_new = base->tp_new; cls->tp_new = base->tp_new;
if (!cls->tp_alloc) {
cls->tp_alloc = reinterpret_cast<decltype(cls->tp_alloc)>(PyType_GenericAlloc);
}
try { try {
add_operators(cls); add_operators(cls);
} catch (Box* b) { } catch (Box* b) {
...@@ -1662,6 +1657,9 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept { ...@@ -1662,6 +1657,9 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
PystonType_Ready(cls); PystonType_Ready(cls);
if (cls->tp_alloc == &PystonType_GenericAlloc)
cls->tp_alloc = &PyType_GenericAlloc;
cls->gc_visit = &conservativeGCHandler; cls->gc_visit = &conservativeGCHandler;
cls->is_user_defined = true; cls->is_user_defined = true;
......
...@@ -355,6 +355,8 @@ BoxedClass::BoxedClass(BoxedClass* base, gcvisit_func gc_visit, int attrs_offset ...@@ -355,6 +355,8 @@ BoxedClass::BoxedClass(BoxedClass* base, gcvisit_func gc_visit, int attrs_offset
tp_flags |= Py_TPFLAGS_HEAPTYPE; tp_flags |= Py_TPFLAGS_HEAPTYPE;
tp_flags |= Py_TPFLAGS_CHECKTYPES; tp_flags |= Py_TPFLAGS_CHECKTYPES;
tp_flags |= Py_TPFLAGS_BASETYPE; tp_flags |= Py_TPFLAGS_BASETYPE;
tp_flags |= Py_TPFLAGS_HAVE_CLASS;
tp_flags |= Py_TPFLAGS_HAVE_GC;
tp_base = base; tp_base = base;
...@@ -3353,8 +3355,10 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) { ...@@ -3353,8 +3355,10 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
PystonType_Ready(made); PystonType_Ready(made);
fixup_slot_dispatchers(made); fixup_slot_dispatchers(made);
made->tp_alloc = base->tp_alloc; if (base->tp_alloc == &PystonType_GenericAlloc)
assert(made->tp_alloc); made->tp_alloc = PystonType_GenericAlloc;
else
made->tp_alloc = PyType_GenericAlloc;
return made; return made;
} }
......
...@@ -37,6 +37,13 @@ slots_tester_init(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -37,6 +37,13 @@ slots_tester_init(PyObject *self, PyObject *args, PyObject *kwds)
return 0; return 0;
} }
static PyObject*
slots_tester_alloc(PyTypeObject* type, Py_ssize_t nitems) {
printf("slots_tester_seq.tp_alloc, %s %ld\n", type->tp_name, nitems);
return PyType_GenericAlloc(type, nitems);
}
static long slots_tester_seq_hash(slots_tester_object* obj) { static long slots_tester_seq_hash(slots_tester_object* obj) {
printf("slots_tester_seq.__hash__\n"); printf("slots_tester_seq.__hash__\n");
return obj->n ^ 1; return obj->n ^ 1;
...@@ -139,7 +146,7 @@ static PyTypeObject slots_tester_seq = { ...@@ -139,7 +146,7 @@ static PyTypeObject slots_tester_seq = {
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
slots_tester_init, /* tp_init */ slots_tester_init, /* tp_init */
0, /* tp_alloc */ (allocfunc)slots_tester_alloc, /* tp_alloc */
slots_tester_new, /* tp_new */ slots_tester_new, /* tp_new */
0, /* tp_free */ 0, /* tp_free */
}; };
......
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