aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2024-04-24 14:01:23 +0200
committerChristian Tismer <tismer@stackless.com>2024-04-24 15:53:11 +0200
commitadb609270e54177024fbcbd9aab7f168a7205dec (patch)
tree0dc6f268453c618e0fd28215fa7f639a44c4af3c /sources/shiboken6
parent0f01e3910b115e4ae48e01eaa0927e42f50180fa (diff)
PEP 697: Use the new type extension provision, amended
The new embedded extra fields were not correctly initialized. For that, an extra meta class was necessary. This bug could not be seen on macOS, probably due to other memory allocation rules. The famous bug_825 is now also fixed. Change-Id: I44ee3b363dda77c4e21951fe2a5385c0368df0cb Task-number: PYSIDE-2230 Fixes: PYSIDE-2676 Pick-to: 6.6 6.7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp38
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.cpp12
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.h3
3 files changed, 33 insertions, 20 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index 5c058c482..3cd8a5c2b 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -129,6 +129,31 @@ 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)},
@@ -166,9 +191,14 @@ static PyTypeObject *createObjectTypeType()
SbkObjectType_Type_slots,
};
- return SbkType_FromSpec(_PepRuntimeVersion() >= 0x030C00 ?
- &SbkObjectType_Type_spec_312 :
- &SbkObjectType_Type_spec);
+ 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);
}
PyTypeObject *SbkObjectType_TypeF(void)
@@ -265,8 +295,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..4b3759456 100644
--- a/sources/shiboken6/libshiboken/pep384impl.cpp
+++ b/sources/shiboken6/libshiboken/pep384impl.cpp
@@ -1092,18 +1092,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;