diff options
author | Christian Tismer <tismer@stackless.com> | 2024-05-02 08:59:20 +0000 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2024-05-02 11:54:36 +0200 |
commit | a11fd997af795363c04007140a0db8923bfc1fa4 (patch) | |
tree | a10252f07d29a729ed24594a545a05b29f4fa389 | |
parent | 391d55abd632492eb50296e3bb061e72d63b1efc (diff) |
Revert "PEP 697: Use the new type extension provision, amended"
This reverts commit adb609270e54177024fbcbd9aab7f168a7205dec.
Reason for revert: The real fix is much simpler and complete.
Change-Id: I07171bcd28fd3f9aa21ddde3130b755aecb62e7d
Pick-to: 6.6 6.7
Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 38 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.cpp | 12 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.h | 3 |
3 files changed, 20 insertions, 33 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index 1ac65c00c..99aea4725 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -197,31 +197,6 @@ static PyGetSetDef SbkObjectType_tp_getset[] = { static PyTypeObject *createObjectTypeType() { - // PYSIDE-2676: When using the new type extension, we need to use an - // extra meta type that provides the extra size. - // This is a hairy part of Python 3.12 . - // - // The problem here is that we use the type extension both in types - // and also in meta types. This was invisible with extender dicts. - // Please study carefully: - // https://docs.python.org/3/c-api/type.html#c.PyType_Spec.basicsize - - PyType_Slot SbkObjectTypeMeta_Type_slots[] = { - {Py_tp_base, static_cast<void *>(&PyType_Type)}, - {Py_tp_alloc, reinterpret_cast<void *>(PyType_GenericAlloc)}, - {0, nullptr} - }; - - PyType_Spec SbkObjectTypeMeta_Type_spec = { - "1:Shiboken.ObjectTypeMeta", - -long(sizeof(SbkObjectTypePrivate)), - 0, // sizeof(PyMemberDef), not for PyPy without a __len__ defined - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_TYPE_SUBCLASS, - SbkObjectTypeMeta_Type_slots, - }; - - auto specMeta = &SbkObjectTypeMeta_Type_spec; - PyType_Slot SbkObjectType_Type_slots[] = { {Py_tp_dealloc, reinterpret_cast<void *>(SbkObjectType_tp_dealloc)}, {Py_tp_getattro, reinterpret_cast<void *>(mangled_type_getattro)}, @@ -259,14 +234,9 @@ static PyTypeObject *createObjectTypeType() SbkObjectType_Type_slots, }; - if (_PepRuntimeVersion() >= 0x030C00) { - auto *meta = SbkType_FromSpec(specMeta); - auto spec = &SbkObjectType_Type_spec_312; - return SbkType_FromSpecWithMeta(spec, meta); - } - - auto spec = &SbkObjectType_Type_spec; - return SbkType_FromSpec(spec); + return SbkType_FromSpec(_PepRuntimeVersion() >= 0x030C00 ? + &SbkObjectType_Type_spec_312 : + &SbkObjectType_Type_spec); } PyTypeObject *SbkObjectType_TypeF(void) @@ -363,6 +333,8 @@ 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 4b3759456..4826fb379 100644 --- a/sources/shiboken6/libshiboken/pep384impl.cpp +++ b/sources/shiboken6/libshiboken/pep384impl.cpp @@ -1092,6 +1092,18 @@ 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 ec58aac81..31fd65219 100644 --- a/sources/shiboken6/libshiboken/pep384impl.h +++ b/sources/shiboken6/libshiboken/pep384impl.h @@ -156,6 +156,9 @@ 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; |