aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2023-10-18 15:45:05 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-10-25 20:51:08 +0000
commita643d923911e595cd60439e075a80a36dc85bc32 (patch)
treeff58e176f9bf7bd980c955a4c11e75d4a889b141
parent4e36f601af645f90feb3418c07645af49d5344fb (diff)
PEP 697: Introduce the SbkObjectType_Check function
By Python 3.12, there is now an official way to extend heap types by custom extra data. In order to make that most effective, we can no longer accept every type in PepType_SOTP, but keep the types carefully apart. This is done with SbkObjectType_Check, which is very rarely necessary. Change-Id: I9cc4b594f2f676712ba92bf7733c4321b717f252 Task-number: PYSIDE-2230 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 29bd6b68ea241ae3a7c29103d8a79d80b79f233c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/libpyside/pyside.cpp2
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp8
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.h3
-rw-r--r--sources/shiboken6/libshiboken/sbkfeature_base.cpp2
4 files changed, 15 insertions, 0 deletions
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index 6d98b63d7..572341e85 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -203,6 +203,8 @@ static QByteArrayList _SbkType_LookupProperty(PyTypeObject *type,
auto len = std::strlen(origName);
for (Py_ssize_t idx = 0; idx < n; idx++) {
PyTypeObject *base = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, idx));
+ if (!SbkObjectType_Check(base))
+ continue;
auto props = SbkObjectType_GetPropertyStrings(base);
if (props == nullptr || *props == nullptr)
continue;
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index 8bd5b7d37..d33f06431 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -652,6 +652,14 @@ PyObject *FallbackRichCompare(PyObject *self, PyObject *other, int op)
return res;
}
+bool SbkObjectType_Check(PyTypeObject *type)
+{
+ static auto *obMeta = reinterpret_cast<PyObject *>(SbkObjectType_TypeF());
+ auto *obType = reinterpret_cast<PyObject *>(type);
+ return obMeta == reinterpret_cast<PyObject *>(Py_TYPE(obType))
+ || PyObject_IsInstance(obType, obMeta);
+}
+
} //extern "C"
diff --git a/sources/shiboken6/libshiboken/basewrapper.h b/sources/shiboken6/libshiboken/basewrapper.h
index 0930830c5..90ec8cb4e 100644
--- a/sources/shiboken6/libshiboken/basewrapper.h
+++ b/sources/shiboken6/libshiboken/basewrapper.h
@@ -110,6 +110,9 @@ LIBSHIBOKEN_API PyObject *FallbackRichCompare(PyObject *self, PyObject *other, i
/// PYSIDE-1970: Be easily able to see what is happening in the running code.
LIBSHIBOKEN_API void disassembleFrame(const char *marker);
+/// PYSIDE-2230: Check if an object is an SbkObject.
+LIBSHIBOKEN_API bool SbkObjectType_Check(PyTypeObject *type);
+
} // extern "C"
namespace Shiboken
diff --git a/sources/shiboken6/libshiboken/sbkfeature_base.cpp b/sources/shiboken6/libshiboken/sbkfeature_base.cpp
index 01b2c0657..acf527e49 100644
--- a/sources/shiboken6/libshiboken/sbkfeature_base.cpp
+++ b/sources/shiboken6/libshiboken/sbkfeature_base.cpp
@@ -207,6 +207,8 @@ static PyObject *lookupUnqualifiedOrOldEnum(PyTypeObject *type, PyObject *name)
for (idx = 0; idx < n; ++idx) {
auto *base = PyTuple_GET_ITEM(mro, idx);
auto *type_base = reinterpret_cast<PyTypeObject *>(base);
+ if (!SbkObjectType_Check(type_base))
+ continue;
auto sotp = PepType_SOTP(type_base);
// The EnumFlagInfo structure tells us if there are Enums at all.
const char **enumFlagInfo = sotp->enumFlagInfo;