diff options
author | Christian Tismer <tismer@stackless.com> | 2023-10-26 23:32:10 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2023-11-14 16:06:04 +0100 |
commit | 9557565b48b2a72b7697443930234f9f92c17781 (patch) | |
tree | e5749eaf58a0c0cd20f5d535ba764c83ee83e37a /sources/shiboken6/libshiboken/basewrapper.cpp | |
parent | a9fac8c9a16c536db36ac2f14a5f9d38e06e6b4c (diff) |
Shiboken: Fix subtle bug caused by PyPy support and "bug_825"
When implementing PyPy support, all Shiboken types lost their
hidden extra fields, because they were replaced by shadow dicts.
This creates a problem with multiple inheritance.
In Python < 3.12, the decision which base type will create the
instance is driven simply by the size of the type. In
class MetaC(MetaA, MetaB):
pass
when MetaA is derived from type and MetaB is derived from
SbkObjectType, MetaA is not the type that should win.
Fixed by simply adding 1 to the default size of PyType_Type.
Caused by bug_825 corrected version.
The old test is retained as bug_825_old.py .
NOTE: This touches a Python 3.8 bug that was fixed in 3.9.12
and 3.10.4 - unfortunately CI Python is older in all cases.
Task-number: PYSIDE-2230
Change-Id: I6e82cafb83c8351bbbeafcc80e11d5e45568f73d
Pick-to: 6.2 6.5 6.6
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'sources/shiboken6/libshiboken/basewrapper.cpp')
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index d33f06431..828c54a89 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -139,11 +139,18 @@ static PyTypeObject *createObjectTypeType() }; // 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. + // In PyPy, it _must_ not be set, because it would have the meanin + // that a `__len__` field must be defined. Not doing so creates + // a hard-to-find crash. + // + // PYSIDE-2230: In Python < 3.12, the decision which base class should create + // the instance is arbitrarily drawn by the size of the type. + // Ignoring this creates a bug in the new version of bug_825 that + // selects the wrong metatype. + // PyType_Spec SbkObjectType_Type_spec = { "1:Shiboken.ObjectType", - 0, + static_cast<int>(PyType_Type.tp_basicsize) + 1, // see above 0, // sizeof(PyMemberDef), not for PyPy without a __len__ defined Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, SbkObjectType_Type_slots, |