diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-01-15 13:13:03 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-01-16 11:20:58 +0100 |
| commit | 8900ff4f627cfa9b0ff2627ba65a655e9ac8c0a8 (patch) | |
| tree | 2da6e012bc6d01033c681bff1743ae601c0dac94 | |
| parent | 68b51b8c9979ceae4367566e476fc50bb5821a05 (diff) | |
Add PepType_GetSlot() wrapping PyType_GetSlot()
PyTypeObject is not exposed in the stable API; PyType_GetSlot()
should be used to retrieve the slots. Unfortunately it only works
for heap types up until 3.10, so introduce a helper
PepType_GetSlot() that replicates the old code depending on runtime
version.
Task-number: PYSIDE-560
Change-Id: I5724b4b868c08b81ba4e2b908fca9ae5419e17b9
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
| -rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.cpp | 33 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.h | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/sources/shiboken6/libshiboken/pep384impl.cpp b/sources/shiboken6/libshiboken/pep384impl.cpp index 66812369d..4826fb379 100644 --- a/sources/shiboken6/libshiboken/pep384impl.cpp +++ b/sources/shiboken6/libshiboken/pep384impl.cpp @@ -1171,6 +1171,39 @@ int PepType_SetDict(PyTypeObject *type, PyObject *dict) return 0; } +// Pre 3.10, PyType_GetSlot() would only work for heap types. +// FIXME: PyType_GetSlot() can be used unconditionally when the +// minimum limited API version is >= 3.10. +void *PepType_GetSlot(PyTypeObject *type, int aSlot) +{ + static const bool is310 = _PepRuntimeVersion() >= 0x030A00; + if (is310 || (type->tp_flags & Py_TPFLAGS_HEAPTYPE) != 0) + return PyType_GetSlot(type, aSlot); + + switch (aSlot) { + case Py_tp_alloc: + return reinterpret_cast<void *>(type->tp_alloc); + case Py_tp_getattro: + return reinterpret_cast<void *>(type->tp_getattro); + case Py_tp_setattro: + return reinterpret_cast<void *>(type->tp_setattro); + case Py_tp_descr_get: + return reinterpret_cast<void *>(type->tp_descr_get); + case Py_tp_descr_set: + return reinterpret_cast<void *>(type->tp_descr_set); + case Py_tp_call: + return reinterpret_cast<void *>(type->tp_call); + case Py_tp_new: + return reinterpret_cast<void *>(type->tp_new); + case Py_tp_init: + return reinterpret_cast<void *>(type->tp_init); + case Py_tp_free: + return reinterpret_cast<void *>(type->tp_free); + } + assert(false); + return nullptr; +} + /*************************************************************************** * * PYSIDE-535: The enum/flag error diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h index fff23d5fa..97372988b 100644 --- a/sources/shiboken6/libshiboken/pep384impl.h +++ b/sources/shiboken6/libshiboken/pep384impl.h @@ -560,6 +560,8 @@ LIBSHIBOKEN_API PyObject *PepType_GetDict(PyTypeObject *type); // is no longer considered to be accessible, we treat it as such. LIBSHIBOKEN_API int PepType_SetDict(PyTypeObject *type, PyObject *dict); +LIBSHIBOKEN_API void *PepType_GetSlot(PyTypeObject *type, int aSlot); + /***************************************************************************** * * Module Initialization |
