From 52f29458d7d6cb379d28d84021819516723d9169 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 18 Jun 2020 09:53:06 +0200 Subject: pthreads: Try to abandon the GIL in case a thread was terminated When terminating a thread using QThread::terminate() via (pthread_cancel(), QThread::run() is aborted and the lock is released, but ~GilState() is still executed for some reason. Add a cancel handler to the thread which tells GilState to abandon the lock. Fixes: PYSIDE-1282 Change-Id: I70abd42b5a2afd49aaa8cc5e8be0a92ed63f49d3 Reviewed-by: Cristian Maureira-Fredes --- .../PySide2/QtCore/typesystem_core_common.xml | 8 ++++++- sources/pyside2/PySide2/glue/qtcore.cpp | 28 ++++++++++++++++++++++ sources/shiboken2/libshiboken/gilstate.cpp | 7 ++++++ sources/shiboken2/libshiboken/gilstate.h | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) (limited to 'sources') diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 26193a0aa..8294947ed 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -1460,9 +1460,15 @@ + - + + + + diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 111e324b9..41ee743e7 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -1960,3 +1960,31 @@ PyTuple_SET_ITEM(%out, 0, %CONVERTTOPYTHON[%INTYPE_0](%in.first)); PyTuple_SET_ITEM(%out, 1, %CONVERTTOPYTHON[%INTYPE_1](%in.second)); return %out; // @snippet return-qpair + +// @snippet qthread_pthread_cleanup +#ifdef Q_OS_UNIX +# include +# include +static void qthread_pthread_cleanup(void *arg) +{ + // PYSIDE 1282: When terminating a thread using QThread::terminate() + // (pthread_cancel()), QThread::run() is aborted and the lock is released, + // but ~GilState() is still executed for some reason. Prevent it from + // releasing. + auto gil = reinterpret_cast(arg); + gil->abandon(); +} +#endif // Q_OS_UNIX +// @snippet qthread_pthread_cleanup + +// @snippet qthread_pthread_cleanup_install +#ifdef Q_OS_UNIX +pthread_cleanup_push(qthread_pthread_cleanup, &gil); +#endif +// @snippet qthread_pthread_cleanup_install + +// @snippet qthread_pthread_cleanup_uninstall +#ifdef Q_OS_UNIX +pthread_cleanup_pop(0); +#endif +// @snippet qthread_pthread_cleanup_uninstall diff --git a/sources/shiboken2/libshiboken/gilstate.cpp b/sources/shiboken2/libshiboken/gilstate.cpp index a59c6f01e..76a4d0e61 100644 --- a/sources/shiboken2/libshiboken/gilstate.cpp +++ b/sources/shiboken2/libshiboken/gilstate.cpp @@ -63,5 +63,12 @@ void GilState::release() } } +// Abandon the lock: Only for special situations, like termination of a +// POSIX thread (PYSIDE 1282). +void GilState::abandon() +{ + m_locked = false; +} + } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/gilstate.h b/sources/shiboken2/libshiboken/gilstate.h index d22f688ba..fbf39ead0 100644 --- a/sources/shiboken2/libshiboken/gilstate.h +++ b/sources/shiboken2/libshiboken/gilstate.h @@ -57,6 +57,7 @@ public: GilState(); ~GilState(); void release(); + void abandon(); private: PyGILState_STATE m_gstate; bool m_locked = false; -- cgit v1.2.3 From b2092a477ff0635c7185037f89361bc6b1c35a36 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 24 Jun 2020 11:47:03 +0200 Subject: Change the return type of the hash functions to Py_ssize_t This is the proper type and makes it clear that it it is not related to Qt's hash type (uint in Qt 5, size_t in Qt 6). Task-number: PYSIDE-904 Change-Id: I4ce0f5c845c06e5dcd0ad9744a16a995017987ef Reviewed-by: Cristian Maureira-Fredes --- sources/pyside2/PySide2/glue/qtcore.cpp | 8 ++++---- sources/pyside2/libpyside/pyside.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'sources') diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index f941d5cfc..f818dcffe 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -647,7 +647,7 @@ if (%PYARG_0 == Py_None) // @snippet qline-hash namespace PySide { - template<> inline uint hash(const QLine &v) { + template<> inline Py_ssize_t hash(const QLine &v) { return qHash(qMakePair(qMakePair(v.x1(), v.y1()), qMakePair(v.x2(), v.y2()))); } }; @@ -715,7 +715,7 @@ if (!PyDateTimeAPI) PySideDateTime_IMPORT; // @snippet qpoint namespace PySide { - template<> inline uint hash(const QPoint &v) { + template<> inline Py_ssize_t hash(const QPoint &v) { return qHash(qMakePair(v.x(), v.y())); } }; @@ -723,7 +723,7 @@ namespace PySide { // @snippet qrect namespace PySide { - template<> inline uint hash(const QRect &v) { + template<> inline Py_ssize_t hash(const QRect &v) { return qHash(qMakePair(qMakePair(v.x(), v.y()), qMakePair(v.width(), v.height()))); } }; @@ -731,7 +731,7 @@ namespace PySide { // @snippet qsize namespace PySide { - template<> inline uint hash(const QSize &v) { + template<> inline Py_ssize_t hash(const QSize &v) { return qHash(qMakePair(v.width(), v.height())); } }; diff --git a/sources/pyside2/libpyside/pyside.h b/sources/pyside2/libpyside/pyside.h index 95abaeeb1..c1a298cc8 100644 --- a/sources/pyside2/libpyside/pyside.h +++ b/sources/pyside2/libpyside/pyside.h @@ -62,7 +62,7 @@ PYSIDE_API void init(PyObject *module); * Hash function used to enable hash on objects not supported on native Qt library which has toString function. */ template -inline uint hash(const T& value) +inline Py_ssize_t hash(const T& value) { return qHash(value.toString()); } -- cgit v1.2.3 From 6e5dddf736ac00ae3981b0ff89d12528d32d8f98 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 24 Jun 2020 11:17:15 +0200 Subject: Add QObject.findChildren(QRegularExpression) Replacing the deprecated QRegExp version in Qt 6. Merge identical code snippets. Task-number: PYSIDE-904 Change-Id: Id6f5c39379c65cf71fb6352531173d0fd7f2ae5e Reviewed-by: Christian Tismer --- sources/pyside2/PySide2/QtCore/typesystem_core_common.xml | 10 ++++++++-- sources/pyside2/PySide2/glue/qtcore.cpp | 14 +++++++------- sources/pyside2/tests/QtCore/qobject_parent_test.py | 7 +++++-- 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'sources') diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index bac210ba7..5d8a1c9c7 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -1723,7 +1723,7 @@ Like the method *findChild*, the first parameter should be the child's type. - + @@ -1732,7 +1732,13 @@ - + + + + + + + diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index f818dcffe..d76f2980e 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -806,6 +806,11 @@ static inline bool _findChildrenComparator(const QObject *&child, const QRegExp return name.indexIn(child->objectName()) != -1; } +static inline bool _findChildrenComparator(const QObject *&child, const QRegularExpression &name) +{ + return name.match(child->objectName()).hasMatch(); +} + static inline bool _findChildrenComparator(const QObject *&child, const QString &name) { return name.isNull() || name == child->objectName(); @@ -828,15 +833,10 @@ QObject *child = _findChildHelper(%CPPSELF, %2, reinterpret_cast %PYARG_0 = %CONVERTTOPYTHON[QObject *](child); // @snippet qobject-findchild-2 -// @snippet qobject-findchildren-1 -%PYARG_0 = PyList_New(0); -_findChildrenHelper(%CPPSELF, %2, reinterpret_cast(%PYARG_1), %PYARG_0); -// @snippet qobject-findchildren-1 - -// @snippet qobject-findchildren-2 +// @snippet qobject-findchildren %PYARG_0 = PyList_New(0); _findChildrenHelper(%CPPSELF, %2, reinterpret_cast(%PYARG_1), %PYARG_0); -// @snippet qobject-findchildren-2 +// @snippet qobject-findchildren // @snippet qobject-tr QString result; diff --git a/sources/pyside2/tests/QtCore/qobject_parent_test.py b/sources/pyside2/tests/QtCore/qobject_parent_test.py index 7e98100a1..0a02fbc26 100644 --- a/sources/pyside2/tests/QtCore/qobject_parent_test.py +++ b/sources/pyside2/tests/QtCore/qobject_parent_test.py @@ -144,10 +144,13 @@ class ParentCase(unittest.TestCase): res = parent.findChildren(QTimer) self.assertEqual(len(res), 20) - # test findChildre with a regex - res = parent.findChildren(QObject, QRegExp("^fo+")) + # test findChildren with a QRegularExpression + res = parent.findChildren(QObject, QRegularExpression("^fo+")) self.assertEqual(res, test_children) + # test findChildren with a QRegExp (deprecated) + res = parent.findChildren(QObject, QRegExp("^fo+")) + self.assertEqual(res, test_children) def testParentEquality(self): #QObject.parent() == parent -- cgit v1.2.3 From 8bf3f03ba1ce0bcdb1b4a3f2edd7ffd672066e1c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 25 Jun 2020 09:48:02 +0200 Subject: signature parser: Catch invalid arguments Triggers in Qt 6 for: QByteArray toHex(char separator = '\0') const; Change-Id: I2f9d7e39cb085d1e602a70449c3ca24b7480bad8 Reviewed-by: Christian Tismer --- .../files.dir/shibokensupport/signature/parser.py | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'sources') diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 2053c3e9d..bfc5b3a30 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -111,17 +111,21 @@ def _parse_line(line): arglist = _parse_arglist(argstr) args = [] for arg in arglist: - name, ann = arg.split(":") - if name in keyword.kwlist: - if LIST_KEYWORDS: - print("KEYWORD", ret) - name = name + "_" - if "=" in ann: - ann, default = ann.split("=", 1) - tup = name, ann, default + tokens = arg.split(":") + if len(tokens) < 2: + warnings.warn('Invalid argument "{}" in "{}".'.format(arg, line)) else: - tup = name, ann - args.append(tup) + name, ann = tokens + if name in keyword.kwlist: + if LIST_KEYWORDS: + print("KEYWORD", ret) + name = name + "_" + if "=" in ann: + ann, default = ann.split("=", 1) + tup = name, ann, default + else: + tup = name, ann + args.append(tup) ret.arglist = args multi = ret.multi if multi is not None: -- cgit v1.2.3