From e2fd134509df0387f12b9b01ec75f30d4e818ddf Mon Sep 17 00:00:00 2001 From: mappu Date: Wed, 18 Sep 2024 13:27:53 +1200 Subject: [PATCH] genbindings/qset: fixes for qset marshalling --- cmd/genbindings/emitcabi.go | 9 +++++---- qt/gen_qstatemachine.cpp | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/genbindings/emitcabi.go b/cmd/genbindings/emitcabi.go index 006da577..e60c6a9d 100644 --- a/cmd/genbindings/emitcabi.go +++ b/cmd/genbindings/emitcabi.go @@ -340,14 +340,15 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string) shouldReturn = p.RenderTypeQtCpp() + " " + namePrefix + "_ret = " afterCall += indent + "// Convert QList<> from C++ memory to manually-managed C memory\n" - afterCall += indent + "" + t.RenderTypeCabi() + "* " + namePrefix + "_arr = static_cast<" + t.RenderTypeCabi() + "*>(malloc(sizeof(" + t.RenderTypeCabi() + ") * " + namePrefix + "_ret.length()));\n" + afterCall += indent + "" + t.RenderTypeCabi() + "* " + namePrefix + "_arr = static_cast<" + t.RenderTypeCabi() + "*>(malloc(sizeof(" + t.RenderTypeCabi() + ") * " + namePrefix + "_ret.size()));\n" afterCall += indent + "int " + namePrefix + "_ctr = 0;\n" - afterCall += indent + "for (const auto " + namePrefix + "_elem& : " + rvalue + " ) {\n" - afterCall += emitAssignCppToCabi(indent+"\t"+namePrefix+"_arr["+namePrefix+"_ctr++] = ", t, namePrefix+"_elem") + afterCall += indent + "QSetIterator<" + t.RenderTypeQtCpp() + "> " + namePrefix + "_itr(" + namePrefix + "_ret);\n" + afterCall += indent + "while (" + namePrefix + "_itr.hasNext()) {\n" + afterCall += emitAssignCppToCabi(indent+"\t"+namePrefix+"_arr["+namePrefix+"_ctr++] = ", t, namePrefix+"_itr.next()") afterCall += indent + "}\n" afterCall += indent + "struct miqt_array* " + namePrefix + "_out = static_cast(malloc(sizeof(struct miqt_array)));\n" - afterCall += indent + "" + namePrefix + "_out->len = " + namePrefix + "_ret.length();\n" + afterCall += indent + "" + namePrefix + "_out->len = " + namePrefix + "_ret.size();\n" afterCall += indent + "" + namePrefix + "_out->data = static_cast(" + namePrefix + "_arr);\n" afterCall += indent + assignExpression + "" + namePrefix + "_out;\n" diff --git a/qt/gen_qstatemachine.cpp b/qt/gen_qstatemachine.cpp index d221652d..8859ceaf 100644 --- a/qt/gen_qstatemachine.cpp +++ b/qt/gen_qstatemachine.cpp @@ -129,13 +129,14 @@ bool QStateMachine_CancelDelayedEvent(QStateMachine* self, int id) { struct miqt_array* QStateMachine_Configuration(const QStateMachine* self) { QSet _ret = self->configuration(); // Convert QList<> from C++ memory to manually-managed C memory - QAbstractState** _arr = static_cast(malloc(sizeof(QAbstractState*) * _ret.length())); + QAbstractState** _arr = static_cast(malloc(sizeof(QAbstractState*) * _ret.size())); int _ctr = 0; - for (const auto _elem& : self->configuration() ) { - _arr[_ctr++] = _elem; + QSetIterator _itr(_ret); + while (_itr.hasNext()) { + _arr[_ctr++] = _itr.next(); } struct miqt_array* _out = static_cast(malloc(sizeof(struct miqt_array))); - _out->len = _ret.length(); + _out->len = _ret.size(); _out->data = static_cast(_arr); return _out; }