aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/pyside.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-06-29 08:34:56 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-06-29 13:56:39 +0200
commit98aef951920641dcdf4c217a0c51626cdf82caf8 (patch)
tree285079d972d5c65e422f83454d80ec139b89e28d /sources/pyside6/libpyside/pyside.cpp
parentba819888cad86b0cacb2a992f01287b476b29a04 (diff)
PySide6: Fix crashes in QObject.findChild()
For all objects encountered in findChild(), a wrapper was created just to be able to retrieve its type object and check against it. As there is a name lookup involved, it happens that non-QObject wrappers are created for this (in the specific case, an enum wrapper), which leads to crashes later on. Refactor the code, extracting a helper function to PySide which finds the best-matching type object for a QObject to check on that. Rearrange the check so that the name is checked first. Pick-to: 6.1 5.15 Fixes: PYSIDE-1609 Change-Id: I026854201f3f6eca9e5905105127f0a4b4588fa9 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/libpyside/pyside.cpp')
-rw-r--r--sources/pyside6/libpyside/pyside.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index 16d77ab57..2026fee53 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -421,7 +421,7 @@ static const char invalidatePropertyName[] = "_PySideInvalidatePtr";
// PYSIDE-1214, when creating new wrappers for classes inheriting QObject but
// not exposed to Python, try to find the best-matching (most-derived) Qt
// class by walking up the meta objects.
-static const char *typeName(QObject *cppSelf)
+static const char *typeName(const QObject *cppSelf)
{
const char *typeName = typeid(*cppSelf).name();
if (!Shiboken::Conversions::getConverter(typeName)) {
@@ -436,6 +436,20 @@ static const char *typeName(QObject *cppSelf)
return typeName;
}
+PyTypeObject *getTypeForQObject(const QObject *cppSelf)
+{
+ // First check if there are any instances of Python implementations
+ // inheriting a PySide class.
+ auto *existing = Shiboken::BindingManager::instance().retrieveWrapper(cppSelf);
+ if (existing != nullptr)
+ return reinterpret_cast<PyObject *>(existing)->ob_type;
+ // Find the best match (will return a PySide type)
+ auto *sbkObjectType = Shiboken::ObjectType::typeForTypeName(typeName(cppSelf));
+ if (sbkObjectType != nullptr)
+ return reinterpret_cast<PyTypeObject *>(sbkObjectType);
+ return nullptr;
+}
+
PyObject *getWrapperForQObject(QObject *cppSelf, SbkObjectType *sbk_type)
{
PyObject *pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppSelf));