diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-06 10:16:02 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-06 09:37:21 +0000 |
commit | c6a8c272d1ad0250d113d466660a4ad191dfaab5 (patch) | |
tree | f736f904e491340d2ee84f574cb5f012e96a2557 /sources | |
parent | 2080387dd8ede7afeaaa5cec52e8b5af4c3e2183 (diff) |
Fix QQmlIncubationController::incubateWhile()
The bool * has been changed into a std::atomic<bool>.
Task-number: PYSIDE-1339
Task-number: PYSIDE-904
Change-Id: Ie64668e145e9233760610985dcb86cea68dfb1f3
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources')
4 files changed, 27 insertions, 23 deletions
diff --git a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp index 4218678bf..5af6abb47 100644 --- a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp +++ b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp @@ -365,18 +365,23 @@ QtQml_VolatileBoolObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds) QtQml_VolatileBoolObject *self = reinterpret_cast<QtQml_VolatileBoolObject *>(type->tp_alloc(type, 0)); - if (self != Q_NULLPTR) - self->flag = ok; + if (self != nullptr) + self->flag = new AtomicBool(ok); return reinterpret_cast<PyObject *>(self); } +static void QtQml_VolatileBoolObject_dealloc(PyObject *self) +{ + auto volatileBool = reinterpret_cast<QtQml_VolatileBoolObject *>(self); + delete volatileBool->flag; + Sbk_object_dealloc(self); +} + static PyObject * QtQml_VolatileBoolObject_get(QtQml_VolatileBoolObject *self) { - if (self->flag) - return Py_True; - return Py_False; + return *self->flag ? Py_True : Py_False; } static PyObject * @@ -395,10 +400,7 @@ QtQml_VolatileBoolObject_set(QtQml_VolatileBoolObject *self, PyObject *args) return Q_NULLPTR; } - if (ok > 0) - self->flag = true; - else - self->flag = false; + *self->flag = ok > 0; Py_RETURN_NONE; } @@ -418,7 +420,7 @@ QtQml_VolatileBoolObject_repr(QtQml_VolatileBoolObject *self) { PyObject *s; - if (self->flag) + if (*self->flag) s = PyBytes_FromFormat("%s(True)", Py_TYPE(self)->tp_name); else @@ -433,12 +435,12 @@ QtQml_VolatileBoolObject_str(QtQml_VolatileBoolObject *self) { PyObject *s; - if (self->flag) + if (*self->flag) s = PyBytes_FromFormat("%s(True) -> %p", - Py_TYPE(self)->tp_name, &(self->flag)); + Py_TYPE(self)->tp_name, self->flag); else s = PyBytes_FromFormat("%s(False) -> %p", - Py_TYPE(self)->tp_name, &(self->flag)); + Py_TYPE(self)->tp_name, self->flag); Py_XINCREF(s); return s; } @@ -448,7 +450,7 @@ static PyType_Slot QtQml_VolatileBoolType_slots[] = { {Py_tp_str, (void *)reinterpret_cast<reprfunc>(QtQml_VolatileBoolObject_str)}, {Py_tp_methods, (void *)QtQml_VolatileBoolObject_methods}, {Py_tp_new, (void *)QtQml_VolatileBoolObject_new}, - {Py_tp_dealloc, (void *)Sbk_object_dealloc}, + {Py_tp_dealloc, (void *)QtQml_VolatileBoolObject_dealloc}, {0, 0} }; static PyType_Spec QtQml_VolatileBoolType_spec = { diff --git a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h index e94ea043f..74690d937 100644 --- a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h +++ b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h @@ -42,6 +42,8 @@ #include <sbkpython.h> +#include <atomic> + struct SbkObjectType; namespace PySide @@ -71,11 +73,13 @@ int qmlRegisterType(PyObject *pyObj, const char *uri, int versionMajor, int vers const char *qmlName); } -// Volatile Bool Ptr type definition. +// Volatile Bool Ptr type definition for QQmlIncubationController::incubateWhile(std::atomic<bool> *, int) + +using AtomicBool = std::atomic<bool>; typedef struct { PyObject_HEAD - volatile bool flag; + AtomicBool *flag; } QtQml_VolatileBoolObject; PyAPI_FUNC(PyTypeObject *) QtQml_VolatileBoolTypeF(void); diff --git a/sources/pyside2/PySide2/QtQml/typesystem_qml.xml b/sources/pyside2/PySide2/QtQml/typesystem_qml.xml index 4ebc4b417..af6f75131 100644 --- a/sources/pyside2/PySide2/QtQml/typesystem_qml.xml +++ b/sources/pyside2/PySide2/QtQml/typesystem_qml.xml @@ -59,12 +59,11 @@ <!-- For qmlEngine(const QObject*), qmlContext(const QObject*) in qqml.h --> <namespace-type name="QtQml"/> - <!-- FIXME Qt 6: expose QQmlIncubationController::incubateWhile() - (see QtQml_VolatileBoolTypeF in pysideqmlregistertype.h) + <!-- expose QQmlIncubationController::incubateWhile() (see + QtQml_VolatileBoolTypeF/pysideqmlregistertype.h) --> <namespace-type name="std" generate="no"> <value-type name="atomic" generate="no"/> </namespace-type> - --> <add-function signature="qmlRegisterType(PyTypeObject,const char*,int,int,const char*)" return-type="int"> <inject-documentation format="target" mode="append"> @@ -162,19 +161,17 @@ <enum-type name="Status"/> </object-type> <object-type name="QQmlIncubationController"> - <!-- FIXME Qt 6 <modify-function signature="incubateWhile(std::atomic<bool>*,int)" allow-thread="yes"> <modify-argument index="1"> The replace type is needed to use the VolatileBool_Check macro instead of a template conversion function with "volatile bool" as argument. <replace-type modified-type="VolatileBool"/> <conversion-rule class="native"> - volatile bool * %out = - &((reinterpret_cast<QtQml_VolatileBoolObject *>(%PYARG_1))->flag); + auto volatileBool = reinterpret_cast<QtQml_VolatileBoolObject *>(%PYARG_1); + std::atomic<bool> *%out = volatileBool->flag; </conversion-rule> </modify-argument> </modify-function> - --> </object-type> <!-- TODO: QQmlListProperty is a template class, and thus should probably be treated like a diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index 0571b11bd..49ea382f6 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -329,6 +329,7 @@ type_map.update({ type_map.update({ # Handling variables that are returned, eventually as Tuples: + "PySide2.QtQml.atomic[bool]": ResultVariable(bool), # QmlIncubationController::incubateWhile() "bool*" : ResultVariable(bool), "float*" : ResultVariable(float), "int*" : ResultVariable(int), |