diff options
| author | Christian Tismer <tismer@stackless.com> | 2024-05-01 15:21:14 +0200 |
|---|---|---|
| committer | Christian Tismer <tismer@stackless.com> | 2024-05-02 11:54:41 +0200 |
| commit | b782c3054fe28f6f23ecab064a700f1da917d88f (patch) | |
| tree | 2c5b09db97ff2add30d5ef501a29fd4c72ee5c8c | |
| parent | a11fd997af795363c04007140a0db8923bfc1fa4 (diff) | |
PEP 697: Use the new type extension provision, final
The new embedded extra fields were not correctly
addressed when a subclass of the meta type was used.
This was fixed by using SbkObjectType explicitly instead
of the type of an object which might be derived. This
also explains the complexity of the Python API.
The famous bug_825 is now fixed, too.
Checked with Valgrind on Ubuntu.
Task-number: PYSIDE-2230
Change-Id: Icf99ed6faab226c72bdd09f4c69018d958ede85e
Fixes: PYSIDE-2676
Pick-to: 6.6 6.7
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
| -rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 2 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.cpp | 20 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.h | 3 |
3 files changed, 6 insertions, 19 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index 99aea4725..6c1d4bf1f 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -333,8 +333,6 @@ static PyTypeObject *createObjectType() offsetof(SbkObject, ob_dict), offsetof(SbkObject, weakreflist), nullptr); // bufferprocs - // Initialize the hidden data area. - _PepPostInit_SbkObject_Type(type); return type; } diff --git a/sources/shiboken6/libshiboken/pep384impl.cpp b/sources/shiboken6/libshiboken/pep384impl.cpp index 4826fb379..f926107e2 100644 --- a/sources/shiboken6/libshiboken/pep384impl.cpp +++ b/sources/shiboken6/libshiboken/pep384impl.cpp @@ -1009,9 +1009,12 @@ long _PepRuntimeVersion() SbkObjectTypePrivate *PepType_SOTP(PyTypeObject *type) { + // PYSIDE-2676: Use the meta type explicitly. + // A derived type would fail the offset calculation. + static auto *meta = SbkObjectType_TypeF(); assert(SbkObjectType_Check(type)); auto *obType = reinterpret_cast<PyObject *>(type); - void *data = PyObject_GetTypeData(obType, Py_TYPE(obType)); + void *data = PyObject_GetTypeData(obType, meta); return reinterpret_cast<SbkObjectTypePrivate *>(data); } @@ -1061,11 +1064,12 @@ static thread_local SbkObjectTypePrivate *SOTP_value{}; SbkObjectTypePrivate *PepType_SOTP(PyTypeObject *type) { + static auto *meta = SbkObjectType_TypeF(); static bool use_312 = _PepRuntimeVersion() >= 0x030C00; assert(SbkObjectType_Check(type)); if (use_312) { auto *obType = reinterpret_cast<PyObject *>(type); - void *data = PepObject_GetTypeData(obType, Py_TYPE(obType)); + void *data = PepObject_GetTypeData(obType, meta); return reinterpret_cast<SbkObjectTypePrivate *>(data); } if (type == SOTP_key) @@ -1092,18 +1096,6 @@ void PepType_SOTP_delete(PyTypeObject *type) #endif // !defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x030C0000 -void _PepPostInit_SbkObject_Type(PyTypeObject *type) -{ - // Special init for SbkObject_Type. - // A normal initialization would recurse PepType_SOTP. - if (_PepRuntimeVersion() >= 0x030C00) { - auto *obType = reinterpret_cast<PyObject *>(type); - void *data = PepObject_GetTypeData(obType, Py_TYPE(obType)); - auto *sbkExt = reinterpret_cast<SbkObjectTypePrivate *>(data); - std::fill_n(reinterpret_cast<char *>(data), sizeof(*sbkExt), 0); - } -} - /* * SbkEnumType extender */ diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h index 31fd65219..ec58aac81 100644 --- a/sources/shiboken6/libshiboken/pep384impl.h +++ b/sources/shiboken6/libshiboken/pep384impl.h @@ -156,9 +156,6 @@ struct SbkObjectTypePrivate; LIBSHIBOKEN_API SbkObjectTypePrivate *PepType_SOTP(PyTypeObject *type); LIBSHIBOKEN_API void PepType_SOTP_delete(PyTypeObject *type); -// PYSIDE-2230: SbkObjectType needs a special init -LIBSHIBOKEN_API void _PepPostInit_SbkObject_Type(PyTypeObject *type); - struct SbkEnumType; struct SbkEnumTypePrivate; |
