From f1bcf7d077282f9248aee570545765ef60af00e3 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 20 Oct 2020 08:01:25 +0200 Subject: 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 --- sources/pyside2/PySide2/QtCore/CMakeLists.txt | 7 +- .../pyside2/PySide2/QtCore/QtCore_global.post.h.in | 1 + .../PySide2/QtCore/typesystem_core_common.xml | 60 +++++++----- sources/pyside2/PySide2/qtcorehelper.h | 106 +++++++++++++++++++++ 4 files changed, 150 insertions(+), 24 deletions(-) create mode 100644 sources/pyside2/PySide2/QtCore/QtCore_global.post.h.in create mode 100644 sources/pyside2/PySide2/qtcorehelper.h (limited to 'sources/pyside2') 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 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 @@ - - - + + + + - + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -2208,11 +2220,13 @@ - - + + + + 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 + +namespace QtCoreHelper { + + using MutexLocker = QMutexLocker; + using RecursiveMutexLocker = QMutexLocker; + + // ::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 -- cgit v1.2.3