aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6
diff options
context:
space:
mode:
authorKyle Altendorf <sda@fstab.net>2021-07-20 14:42:33 -0400
committerChristian Tismer <tismer@stackless.com>2021-10-29 11:51:45 +0200
commite9b29a35eb483b19dc3fac7c815d87a3afacdcfd (patch)
tree6441884f36702d85befea692f22823f6ea29a072 /sources/pyside6
parent07f9b2b674aca4f1d7b5f81ce25e1db08b165249 (diff)
Fix equality test for inherited signals
The signal initialization code didn't walk the MRO so it only caught directly defined signals, not inherited signals. Walking the MRO to find all signals resolves this issue. Fixes: PYSIDE-1431 Pick-to: 6.2 Change-Id: Iadba9760e81f88478da4f3ac30e9885c4f568df5 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6')
-rw-r--r--sources/pyside6/libpyside/pysidesignal.cpp37
-rw-r--r--sources/pyside6/tests/QtCore/CMakeLists.txt1
-rw-r--r--sources/pyside6/tests/QtCore/signalinstance_equality_test.py68
3 files changed, 96 insertions, 10 deletions
diff --git a/sources/pyside6/libpyside/pysidesignal.cpp b/sources/pyside6/libpyside/pysidesignal.cpp
index 2a8635666..78f4d2a89 100644
--- a/sources/pyside6/libpyside/pysidesignal.cpp
+++ b/sources/pyside6/libpyside/pysidesignal.cpp
@@ -742,21 +742,38 @@ bool checkInstanceType(PyObject *pyObj)
void updateSourceObject(PyObject *source)
{
- PyTypeObject *objType = reinterpret_cast<PyTypeObject *>(PyObject_Type(source));
+ // TODO: Provide for actual upstream exception handling.
+ // For now we'll just return early to avoid further issues.
- Py_ssize_t pos = 0;
- PyObject *value;
- PyObject *key;
+ if (source == nullptr) // Bad input
+ return;
- while (PyDict_Next(objType->tp_dict, &pos, &key, &value)) {
- if (PyObject_TypeCheck(value, PySideSignalTypeF())) {
- Shiboken::AutoDecRef signalInstance(reinterpret_cast<PyObject *>(PyObject_New(PySideSignalInstance, PySideSignalInstanceTypeF())));
- instanceInitialize(signalInstance.cast<PySideSignalInstance *>(), key, reinterpret_cast<PySideSignal *>(value), source, 0);
- PyObject_SetAttr(source, key, signalInstance);
+ Shiboken::AutoDecRef mroIterator(PyObject_GetIter(source->ob_type->tp_mro));
+
+ if (mroIterator.isNull()) // Not iterable
+ return;
+
+ Shiboken::AutoDecRef mroItem{};
+
+ while ((mroItem.reset(PyIter_Next(mroIterator))), mroItem.object()) {
+ Py_ssize_t pos = 0;
+ PyObject *key, *value;
+ auto *type = reinterpret_cast<PyTypeObject *>(mroItem.object());
+
+ while (PyDict_Next(type->tp_dict, &pos, &key, &value)) {
+ if (PyObject_TypeCheck(value, PySideSignalTypeF())) {
+ auto *inst = PyObject_New(PySideSignalInstance, PySideSignalInstanceTypeF());
+ Shiboken::AutoDecRef signalInstance(reinterpret_cast<PyObject *>(inst));
+ instanceInitialize(signalInstance.cast<PySideSignalInstance *>(),
+ key, reinterpret_cast<PySideSignal *>(value), source, 0);
+ if (PyObject_SetAttr(source, key, signalInstance) == -1)
+ return; // An error occurred while setting the attribute
+ }
}
}
- Py_XDECREF(objType);
+ if (PyErr_Occurred()) // An iteration error occurred
+ return;
}
QByteArray getTypeName(PyObject *obType)
diff --git a/sources/pyside6/tests/QtCore/CMakeLists.txt b/sources/pyside6/tests/QtCore/CMakeLists.txt
index cf7e91e30..c5e33faf9 100644
--- a/sources/pyside6/tests/QtCore/CMakeLists.txt
+++ b/sources/pyside6/tests/QtCore/CMakeLists.txt
@@ -131,6 +131,7 @@ PYSIDE_TEST(translation_test.py)
PYSIDE_TEST(unaryoperator_test.py)
PYSIDE_TEST(unicode_test.py)
PYSIDE_TEST(versioninfo_test.py)
+PYSIDE_TEST(signalinstance_equality_test.py)
if(X11)
PYSIDE_TEST(qhandle_test.py)
diff --git a/sources/pyside6/tests/QtCore/signalinstance_equality_test.py b/sources/pyside6/tests/QtCore/signalinstance_equality_test.py
new file mode 100644
index 000000000..7743157a1
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/signalinstance_equality_test.py
@@ -0,0 +1,68 @@
+#############################################################################
+##
+## Copyright (C) 2021 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QFile, QObject, QTimer, Signal
+
+
+class C(QObject):
+ custom_signal = Signal()
+
+
+class D(C):
+ pass
+
+
+class TestVersionInfo(unittest.TestCase):
+ def test_signal_instances_are_equal(self):
+ o = QTimer()
+ self.assertTrue(o.timeout == o.timeout)
+
+ def test_inherited_signal_instances_are_equal(self):
+ o = QFile()
+ self.assertTrue(o.readyRead == o.readyRead)
+
+ def test_custom_signal_instances_are_equal(self):
+ o = C()
+ self.assertTrue(o.custom_signal == o.custom_signal)
+
+ def test_custom_inherited_signal_instances_are_equal(self):
+ o = D()
+ self.assertTrue(o.custom_signal == o.custom_signal)
+
+
+if __name__ == '__main__':
+ unittest.main()