diff options
Diffstat (limited to 'sources/pyside6/libpysideqml/pysideqmllistproperty.cpp')
-rw-r--r-- | sources/pyside6/libpysideqml/pysideqmllistproperty.cpp | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp b/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp index a23b1af42..75bb5af96 100644 --- a/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp +++ b/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp @@ -5,6 +5,7 @@ #include "pysideqmlregistertype_p.h" #include <shiboken.h> +#include <pep384ext.h> #include <signature.h> #include <pysideproperty.h> @@ -33,30 +34,51 @@ extern "C" static PyObject *propList_tp_new(PyTypeObject *subtype, PyObject * /* args */, PyObject * /* kwds */) { - PySideProperty *me = reinterpret_cast<PySideProperty *>(subtype->tp_alloc(subtype, 0)); + auto *me = PepExt_TypeCallAlloc<PySideProperty>(subtype, 0); me->d = new QmlListPropertyPrivate; return reinterpret_cast<PyObject *>(me); } static int propListTpInit(PyObject *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"type", "append", "count", "at", "clear", "replace", "removeLast", 0}; + static const char *kwlist[] = {"type", "append", "count", "at", "clear", + "replace", "removeLast", + "doc", "notify", // PySideProperty + "designable", "scriptable", "stored", + "user", "constant", "final", + nullptr}; PySideProperty *pySelf = reinterpret_cast<PySideProperty *>(self); auto *data = static_cast<QmlListPropertyPrivate *>(pySelf->d); + char *doc{}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, - "O|OOOOOO:QtQml.ListProperty", (char **) kwlist, + "O|OOOOOOsObbbbbb:QtQml.ListProperty", + const_cast<char **>(kwlist), &data->type, &data->append, &data->count, &data->at, &data->clear, &data->replace, - &data->removeLast)) { + &data->removeLast, + /*s*/ &doc, + /*O*/ &(data->notify), // PySideProperty + /*bbb*/ &(data->designable), + &(data->scriptable), + &(data->stored), + /*bbb*/ &(data->user), + &(data->constant), + &(data->final))) { return -1; } + if (doc) + data->doc = doc; + else + data->doc.clear(); + PyTypeObject *qobjectType = qObjectType(); if (!PySequence_Contains(data->type->tp_mro, reinterpret_cast<PyObject *>(qobjectType))) { @@ -80,24 +102,31 @@ static int propListTpInit(PyObject *self, PyObject *args, PyObject *kwds) return 0; } -static PyType_Slot PropertyListType_slots[] = { - {Py_tp_new, reinterpret_cast<void *>(propList_tp_new)}, - {Py_tp_init, reinterpret_cast<void *>(propListTpInit)}, - {0, nullptr} -}; -static PyType_Spec PropertyListType_spec = { - "2:PySide6.QtQml.ListProperty", - sizeof(PySideProperty), - 0, - Py_TPFLAGS_DEFAULT, - PropertyListType_slots, -}; - +static PyTypeObject *createPropertyListType() +{ + PyType_Slot PropertyListType_slots[] = { + {Py_tp_new, reinterpret_cast<void *>(propList_tp_new)}, + {Py_tp_init, reinterpret_cast<void *>(propListTpInit)}, + {0, nullptr} + }; + + PyType_Spec PropertyListType_spec = { + "2:PySide6.QtQml.ListProperty", + sizeof(PySideProperty), + 0, + Py_TPFLAGS_DEFAULT, + PropertyListType_slots, + }; + + Shiboken::AutoDecRef bases(Py_BuildValue("(O)", PySideProperty_TypeF())); + return SbkType_FromSpecWithBases(&PropertyListType_spec, bases.object()); +} PyTypeObject *PropertyList_TypeF(void) { - static Shiboken::AutoDecRef bases(Py_BuildValue("(O)", PySideProperty_TypeF())); - static auto *type = SbkType_FromSpecWithBases(&PropertyListType_spec, bases); + // PYSIDE-2230: This was a wrong replacement by static AutoDecref. + // Never do that, deletes things way too late. + static PyTypeObject *type = createPropertyListType(); return type; } @@ -140,7 +169,7 @@ qsizetype propListCount(QQmlListProperty<QObject> *propList) return 0; } - int cppResult = 0; + qsizetype cppResult = 0; auto *converter = Shiboken::Conversions::PrimitiveTypeConverter<qsizetype>(); if (auto *pythonToCpp = Shiboken::Conversions::isPythonToCppConvertible(converter, retVal)) pythonToCpp(retVal, &cppResult); |