aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/libshiboken/basewrapper.cpp
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-09-24 18:45:08 +0200
committerChristian Tismer <tismer@stackless.com>2021-09-27 10:52:43 +0200
commitf4532d9253aabd12fbb17fb94b80b0e48b08e8db (patch)
tree6af2ed354181110172cc6c57ea7a66759ba84f60 /sources/shiboken6/libshiboken/basewrapper.cpp
parent3fa8b76268937400523f3e10d9410f050de4c2af (diff)
PyPySide: Fix a hard-to-find bug triggered by tp_itemsize
In a metatype (a type inheriting from PyType_Type), it is common to set tp_itemsize to sizeof(PyMemberDef). This is not necessary, since tp_itemsize is otherwise inherited. In PyPy, tp_itemsize also has the undocumented meaning that the type must define a `__len__` field. Not doing so results in a barely understandable error message, and all types created in PySide crash, resulting in many failing tests. As a conclusion: The tp_itemsize field must stay zero in our metatypes. This bug was very hard to find. Many thanks for a hint from Ronan Lamy wo is an experienced PyPy developer. He saw the problem almost immediately. [ChangeLog][shiboken6] A hard-to-find incompatibility to PyPy in meta type creation was fixed. Many thanks to Ronan Lamy from the PyPy group. Task-number: PYSIDE-535 Change-Id: I99520b96c80d22195948d96cfb41b7b85c6815fa Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6/libshiboken/basewrapper.cpp')
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index 90cb16ef5..fa60455db 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -152,10 +152,14 @@ static PyType_Slot SbkObjectType_Type_slots[] = {
{Py_tp_getset, reinterpret_cast<void *>(SbkObjectType_Type_getsetlist)},
{0, nullptr}
};
+
+// PYSIDE-535: The tp_itemsize field is inherited and does not need to be set.
+// In PyPy, it _must_ not be set, because it would have the meaning that a
+// `__len__` field must be defined. Not doing so creates a hard-to-find crash.
static PyType_Spec SbkObjectType_Type_spec = {
"1:Shiboken.ObjectType",
0,
- sizeof(PyMemberDef),
+ 0, // sizeof(PyMemberDef), not for PyPy without a __len__ defined
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
SbkObjectType_Type_slots,
};