From 01b991ec1ea68b67589c2f93acf1f7704c516dd5 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 11 Jun 2021 17:25:21 +0200 Subject: Handle AOT functions returning QVariant in bindings We need to write the inner data of the variant. Otherwise we create double-wrapped objects. Change-Id: Iacc7b341168c4328172a4e442c16cfbedc6c36c0 Reviewed-by: Fabian Kosmale Reviewed-by: Andrei Golubev (cherry picked from commit c83249da39ed1ec33bfb35cd630f6b3c0facf7a3) Reviewed-by: Qt Cherry-pick Bot --- src/qml/qml/qqmlbinding.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 788d03b8e2..3212dc5604 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -259,15 +259,24 @@ protected: const QV4::Function *v4Function = function(); if (v4Function && v4Function->aotFunction && !hasBoundFunction()) { const auto returnType = v4Function->aotFunction->returnType; - const auto size = returnType.sizeOf(); - if (Q_LIKELY(size > 0)) { - Q_ALLOCA_VAR(void, result, size); + if (returnType == QMetaType::fromType()) { + // It expects uninitialized memory + Q_ALLOCA_VAR(QVariant, result, sizeof(QVariant)); const bool isUndefined = !evaluate(result, returnType); if (canWrite()) - error = !write(result, returnType, isUndefined, flags); - returnType.destruct(result); - } else if (canWrite()) { - error = !write(QV4::Encode::undefined(), true, flags); + error = !write(result->data(), result->metaType(), isUndefined, flags); + result->~QVariant(); + } else { + const auto size = returnType.sizeOf(); + if (Q_LIKELY(size > 0)) { + Q_ALLOCA_VAR(void, result, size); + const bool isUndefined = !evaluate(result, returnType); + if (canWrite()) + error = !write(result, returnType, isUndefined, flags); + returnType.destruct(result); + } else if (canWrite()) { + error = !write(QV4::Encode::undefined(), true, flags); + } } } else { bool isUndefined = false; -- cgit v1.2.3