diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-20 08:01:25 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-20 10:15:00 +0000 |
commit | f1bcf7d077282f9248aee570545765ef60af00e3 (patch) | |
tree | a75434bdd6269bd507ac14e156212a8b32e5f066 | |
parent | 4c93e4299eb210e98adc02d1e02c134e29464537 (diff) |
Fix QMutexLocker
qtbase/d4b206b246caf9b49110526585693ab629609d99 split QMutex and
QRecursiveMutex which inherited from each other in Qt 5 into
separate classes and changed QMutexLocker into a template.
This could only be represented by separate types in Python.
To work around this, reconstruct a QMutexLocker with the common API
into an invisible namespace for generating the bindings.
Task-number: PYSIDE-1339
Task-number: PYSIDE-904
Change-Id: I776250f91dfed9985f2a8a5705b26f782a20bbd9
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/pyside2/PySide2/QtCore/CMakeLists.txt | 7 | ||||
-rw-r--r-- | sources/pyside2/PySide2/QtCore/QtCore_global.post.h.in | 1 | ||||
-rw-r--r-- | sources/pyside2/PySide2/QtCore/typesystem_core_common.xml | 60 | ||||
-rw-r--r-- | sources/pyside2/PySide2/qtcorehelper.h | 106 |
4 files changed, 150 insertions, 24 deletions
diff --git a/sources/pyside2/PySide2/QtCore/CMakeLists.txt b/sources/pyside2/PySide2/QtCore/CMakeLists.txt index e8356b9d8..b6a374073 100644 --- a/sources/pyside2/PySide2/QtCore/CMakeLists.txt +++ b/sources/pyside2/PySide2/QtCore/CMakeLists.txt @@ -95,7 +95,6 @@ ${QtCore_GEN_DIR}/qmimedatabase_wrapper.cpp ${QtCore_GEN_DIR}/qmimetype_wrapper.cpp ${QtCore_GEN_DIR}/qmodelindex_wrapper.cpp ${QtCore_GEN_DIR}/qmutex_wrapper.cpp -${QtCore_GEN_DIR}/qmutexlocker_wrapper.cpp ${QtCore_GEN_DIR}/qobject_wrapper.cpp ${QtCore_GEN_DIR}/qoperatingsystemversion_wrapper.cpp ${QtCore_GEN_DIR}/qparallelanimationgroup_wrapper.cpp @@ -137,6 +136,7 @@ ${QtCore_GEN_DIR}/qstringlistmodel_wrapper.cpp ${QtCore_GEN_DIR}/qsysinfo_wrapper.cpp ${QtCore_GEN_DIR}/qsystemsemaphore_wrapper.cpp ${QtCore_GEN_DIR}/qt_wrapper.cpp +${QtCore_GEN_DIR}/qtcorehelper_qmutexlocker_wrapper.cpp ${QtCore_GEN_DIR}/qtemporarydir_wrapper.cpp ${QtCore_GEN_DIR}/qtemporaryfile_wrapper.cpp ${QtCore_GEN_DIR}/qtextboundaryfinder_wrapper.cpp @@ -173,6 +173,9 @@ ${SPECIFIC_OS_FILES} ${QtCore_GEN_DIR}/qtcore_module_wrapper.cpp ) +configure_file("${QtCore_SOURCE_DIR}/QtCore_global.post.h.in" + "${QtCore_BINARY_DIR}/QtCore_global.post.h" @ONLY) + set(QtCore_glue_sources "${QtCore_SOURCE_DIR}/glue/qeasingcurve_glue.cpp" "${QtCore_SOURCE_DIR}/glue/qeasingcurve_glue.h" @@ -184,6 +187,7 @@ configure_file("${QtCore_SOURCE_DIR}/typesystem_core.xml.in" set(QtCore_include_dirs ${QtCore_SOURCE_DIR} ${QtCore_BINARY_DIR} ${Qt${QT_MAJOR_VERSION}Core_INCLUDE_DIRS} + ${pyside2_SOURCE_DIR} ${libpyside_SOURCE_DIR} ) set(QtCore_libraries pyside2 @@ -200,3 +204,4 @@ create_pyside_module(NAME QtCore GLUE_SOURCES QtCore_glue_sources ) +install(FILES ${pyside2_SOURCE_DIR}/qtcorehelper.h DESTINATION include/PySide2/QtCore/) diff --git a/sources/pyside2/PySide2/QtCore/QtCore_global.post.h.in b/sources/pyside2/PySide2/QtCore/QtCore_global.post.h.in new file mode 100644 index 000000000..55a49bb88 --- /dev/null +++ b/sources/pyside2/PySide2/QtCore/QtCore_global.post.h.in @@ -0,0 +1 @@ +#include <qtcorehelper.h> diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 144e16ffc..daa636f98 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -2177,29 +2177,41 @@ <inject-code class="target" position="end" file="../glue/qtcore.cpp" snippet="qlibraryinfo_build"/> </modify-function> </object-type> - <object-type name="QMutexLocker" copyable="no"> - <!-- PYSIDE-1271: Creating locking capable objects inside sections that - contain allow-thread, require the classes to also allow having threads. - The lack of the option here, was generating a deadlock when running a - QMutexLocker inside a QThread::run. - The reason of having this change is due to the new way of handling the GIL - in the Qt calls on the whole PySide2 module, that started on 5.14.2--> - <modify-function signature="QMutexLocker(QBasicMutex*)" allow-thread="yes"> + <namespace-type name="QtCoreHelper" visible="no"> + <object-type name="QMutexLocker" copyable="no"> + <!-- PYSIDE-1271: Creating locking capable objects inside sections that + contain allow-thread, require the classes to also allow having threads. + The lack of the option here, was generating a deadlock when running a + QMutexLocker inside a QThread::run. + The reason of having this change is due to the new way of handling the GIL + in the Qt calls on the whole PySide2 module, that started on 5.14.2--> + <modify-function signature="QMutexLocker(QMutex*)" allow-thread="yes"> <modify-argument index="1"> - <reference-count action="set" variable-name="mutex()const0"/> + <reference-count action="set" variable-name="mutex()const0"/> </modify-argument> - </modify-function> - <modify-function signature="relock()" allow-thread="yes"/> - <modify-function signature="mutex()const"> - <modify-argument index="return"> - <reference-count action="set"/> - </modify-argument> - </modify-function> - <add-function signature="__enter__()"/> - <add-function signature="__exit__(PyObject*,PyObject*,PyObject*)"> - <inject-code file="../glue/qtcore.cpp" snippet="unlock"/> - </add-function> - </object-type> + </modify-function> + <modify-function signature="QMutexLocker(QRecursiveMutex*)" allow-thread="yes"> + <modify-argument index="1"> + <reference-count action="set" variable-name="recursiveMutex()const0"/> + </modify-argument> + </modify-function> + <modify-function signature="relock()" allow-thread="yes"/> + <modify-function signature="mutex()const"> + <modify-argument index="return"> + <reference-count action="set"/> + </modify-argument> + </modify-function> + <modify-function signature="recursiveMutex()const"> + <modify-argument index="return"> + <reference-count action="set"/> + </modify-argument> + </modify-function> + <add-function signature="__enter__()"/> + <add-function signature="__exit__(PyObject*,PyObject*,PyObject*)"> + <inject-code file="../glue/qtcore.cpp" snippet="unlock"/> + </add-function> + </object-type> + </namespace-type> <!-- Qt5 addition --> <object-type name="QBasicMutex"> @@ -2208,11 +2220,13 @@ </object-type> <object-type name="QMutex"> - <enum-type name="RecursionMode"/> <modify-function signature="lock()" allow-thread="yes"/> <modify-function signature="tryLock(int)" allow-thread="yes"/> </object-type> - <object-type name="QRecursiveMutex" since="5.14"/> + <object-type name="QRecursiveMutex" since="5.14"> + <modify-function signature="lock()" allow-thread="yes"/> + <modify-function signature="tryLock(int)" allow-thread="yes"/> + </object-type> <object-type name="QRandomGenerator" since="5.10"> <modify-function signature="global()" rename="global_"/> <modify-function signature="operator()()" remove="all"/> diff --git a/sources/pyside2/PySide2/qtcorehelper.h b/sources/pyside2/PySide2/qtcorehelper.h new file mode 100644 index 000000000..22b87fc0e --- /dev/null +++ b/sources/pyside2/PySide2/qtcorehelper.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTCOREHELPER_H +#define QTCOREHELPER_H + +#include <QtCore/qmutex.h> + +namespace QtCoreHelper { + + using MutexLocker = QMutexLocker<QMutex>; + using RecursiveMutexLocker = QMutexLocker<QRecursiveMutex>; + + // ::QMutexLocker is a template with the QMutex class as parameter which can + // only be represented by different type names in Python. Provide a common API. + class QMutexLocker + { + public: + Q_DISABLE_COPY_MOVE(QMutexLocker) + + explicit QMutexLocker(QMutex *m) + : m_mutexLocker(new MutexLocker(m)) + { + } + + explicit QMutexLocker(QRecursiveMutex *m) + : m_recursiveMutexLocker(new RecursiveMutexLocker(m)) + { + } + + void unlock() + { + if (m_mutexLocker) + m_mutexLocker->unlock(); + else + m_recursiveMutexLocker->unlock(); + } + + void relock() + { + if (m_mutexLocker) + m_mutexLocker->relock(); + else + m_recursiveMutexLocker->relock(); + } + + QMutex *mutex() const + { + return m_mutexLocker ? m_mutexLocker->mutex() : nullptr; + } + + QRecursiveMutex *recursiveMutex() const + { + return m_recursiveMutexLocker ? m_recursiveMutexLocker->mutex() : nullptr; + } + + ~QMutexLocker() + { + delete m_mutexLocker; + delete m_recursiveMutexLocker; + } + + private: + MutexLocker *m_mutexLocker = nullptr; + RecursiveMutexLocker *m_recursiveMutexLocker = nullptr; + }; + +} // namespace QtCoreHelper + +#endif // QTCOREHELPER_H |