diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-08-28 15:37:45 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-09-05 07:52:47 +0200 |
commit | a1d389570f78d5bd1fb73cd58678498461555f8e (patch) | |
tree | 8bca3d128de9813ba392ff09fe930455f3b59c9e /sources/pyside6/libpyside/dynamicqmetaobject.cpp | |
parent | 89fd464e6c56deb29d60ef295dbfbbe3b70f0303 (diff) |
libpyside: Refactor passing slot data between @Slot and MetaObjectBuilder
The slot data required for MetaObjectBuilder were stored in a PyList
set as an attribute on a method. This required concatenating return
type and signature, converting the resulting string to CPython in the
@Slot code and converting it back to QByteArray in MetaObjectBuilder.
To simplify this, introduce a small C++ struct storing the QByteArrays
and store a list of them as a PyCapsule (encapsulating a void *ptr)
which is used as the attribute value.
Task-number: PYSIDE-748
Change-Id: I7f4075f5e828fe543d01e5dfbdc7087905cd004f
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside/dynamicqmetaobject.cpp')
-rw-r--r-- | sources/pyside6/libpyside/dynamicqmetaobject.cpp | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/sources/pyside6/libpyside/dynamicqmetaobject.cpp b/sources/pyside6/libpyside/dynamicqmetaobject.cpp index 5a4c339b2..a0eaba902 100644 --- a/sources/pyside6/libpyside/dynamicqmetaobject.cpp +++ b/sources/pyside6/libpyside/dynamicqmetaobject.cpp @@ -24,6 +24,8 @@ #include <cstring> #include <vector> +using namespace Qt::StringLiterals; + using namespace PySide; // MetaObjectBuilder: Provides the QMetaObject's returned by @@ -215,7 +217,8 @@ int MetaObjectBuilderPrivate::addSlot(const QByteArray &signature, return -1; m_dirty = true; QMetaMethodBuilder methodBuilder = ensureBuilder()->addSlot(signature); - methodBuilder.setReturnType(type); + if (!type.isEmpty() && type != "void"_ba) + methodBuilder.setReturnType(type); return m_baseObject->methodCount() + methodBuilder.index(); } @@ -628,24 +631,11 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type) // PYSIDE-198: PyFunction_Check does not work with Nuitka. // Register slots. if (PyObject_HasAttr(value, slotAttrName)) { - PyObject *signatureList = PyObject_GetAttr(value, slotAttrName); - for (Py_ssize_t i = 0, i_max = PyList_Size(signatureList); i < i_max; ++i) { - PyObject *pySignature = PyList_GET_ITEM(signatureList, i); - QByteArray signature(String::toCString(pySignature)); - // Split the slot type and its signature. - QByteArray type; - const int spacePos = signature.indexOf(' '); - if (spacePos != -1) { - type = signature.left(spacePos); - signature.remove(0, spacePos + 1); - } - const int index = m_baseObject->indexOfSlot(signature); - if (index == -1) { - if (type.isEmpty() || type == "void") - addSlot(signature); - else - addSlot(signature, type); - } + auto *capsule = PyObject_GetAttr(value, slotAttrName); + const auto *entryList = PySide::Slot::dataListFromCapsule(capsule); + for (const auto &e : *entryList) { + if (m_baseObject->indexOfSlot(e.signature) == -1) + addSlot(e.signature, e.resultType); } } } |