diff options
5 files changed, 16 insertions, 11 deletions
diff --git a/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp b/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp index 3ccbe69a4..edca30620 100644 --- a/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp +++ b/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp @@ -51,18 +51,15 @@ #include <QtCore/QMutex> -// Mutex used to avoid race condition on PySide::nextQObjectMemoryAddr. -static QMutex nextQmlElementMutex; - static void createQuickItem(void *memory, void *type) { - QMutexLocker locker(&nextQmlElementMutex); + QMutexLocker locker(&PySide::nextQObjectMemoryAddrMutex()); PySide::setNextQObjectMemoryAddr(memory); Shiboken::GilState state; PyObject *obj = PyObject_CallObject(reinterpret_cast<PyObject *>(type), 0); if (!obj || PyErr_Occurred()) PyErr_Print(); - PySide::setNextQObjectMemoryAddr(0); + PySide::setNextQObjectMemoryAddr(nullptr); } bool pyTypeObjectInheritsFromClass(PyTypeObject *pyObjType, QByteArray className) diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp index 05c0e7486..b2bf0ed69 100644 --- a/sources/pyside6/libpyside/pyside.cpp +++ b/sources/pyside6/libpyside/pyside.cpp @@ -71,6 +71,7 @@ #include <QtCore/QCoreApplication> #include <QtCore/QDir> #include <QtCore/QFileInfo> +#include <QtCore/QMutex> #include <QtCore/QSharedPointer> #include <QtCore/QStack> #include <QtCore/QThread> @@ -387,6 +388,12 @@ bool inherits(PyTypeObject *objType, const char *class_name) return inherits(base, class_name); } +QMutex &nextQObjectMemoryAddrMutex() +{ + static QMutex mutex; + return mutex; +} + void *nextQObjectMemoryAddr() { return qobjectNextAddr; diff --git a/sources/pyside6/libpyside/pysideqobject.h b/sources/pyside6/libpyside/pysideqobject.h index 19e603bb7..538f6f024 100644 --- a/sources/pyside6/libpyside/pysideqobject.h +++ b/sources/pyside6/libpyside/pysideqobject.h @@ -48,6 +48,7 @@ QT_FORWARD_DECLARE_CLASS(QObject) QT_FORWARD_DECLARE_STRUCT(QMetaObject) +QT_FORWARD_DECLARE_CLASS(QMutex) namespace PySide { @@ -83,7 +84,10 @@ PYSIDE_API QObject *convertToQObject(PyObject *object, bool raiseError); /// attribute related with name PYSIDE_API PyObject *getMetaDataFromQObject(QObject *cppSelf, PyObject *self, PyObject *name); +/// Mutex for accessing QObject memory helpers from multiple threads +PYSIDE_API QMutex &nextQObjectMemoryAddrMutex(); PYSIDE_API void *nextQObjectMemoryAddr(); +/// Set the address where to allocate the next QObject (for QML) PYSIDE_API void setNextQObjectMemoryAddr(void *addr); PYSIDE_API PyObject *getWrapperForQObject(QObject *cppSelf, PyTypeObject *sbk_type); diff --git a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp index cbacd5887..5f5d5fff8 100644 --- a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp +++ b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp @@ -59,20 +59,17 @@ #include <QtQml/QJSValue> #include <QtQml/QQmlListProperty> -// Mutex used to avoid race condition on PySide::nextQObjectMemoryAddr. -static QMutex nextQmlElementMutex; - static PySide::Qml::QuickRegisterItemFunction quickRegisterItemFunction = nullptr; static void createInto(void *memory, void *type) { - QMutexLocker locker(&nextQmlElementMutex); + QMutexLocker locker(&PySide::nextQObjectMemoryAddrMutex()); PySide::setNextQObjectMemoryAddr(memory); Shiboken::GilState state; PyObject *obj = PyObject_CallObject(reinterpret_cast<PyObject *>(type), 0); if (!obj || PyErr_Occurred()) PyErr_Print(); - PySide::setNextQObjectMemoryAddr(0); + PySide::setNextQObjectMemoryAddr(nullptr); } PyTypeObject *qObjectType() diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index e508b5855..f93024d55 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -3679,7 +3679,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr Indentation indent(uva); uva << "cptr = new (addr) ::" << ctorCall << ";\n" - << "PySide::setNextQObjectMemoryAddr(0);" + << "PySide::setNextQObjectMemoryAddr(nullptr);" << '\n'; } uva << "} else {\n"; |