From 75d324cbb9ad4f1c5781bf8b5f6c178b29030b70 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Tue, 20 Feb 2024 17:03:50 +0100 Subject: [PATCH] qtwaylandscanner: Send null for a null QString with allow-null `toUtf8().constData()` on a null `QString` results in an empty string sent over the wire, which is distinct from `null` when the request has "allow-null" specified. Notably `wl_data_offer.accept` uses a null mime_type for "not accepted". [ChangeLog][Important Behavior Changes][qtwaylandscanner] String arguments in a request will now send null rather than empty string for a null QString if the argument is declared with "allow-null". Change-Id: I4b78246e4da7b60680d7797fd6309755f44d2bb6 Reviewed-by: David Edmundson --- .../qtwaylandscanner/qtwaylandscanner.cpp | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/tools/qtwaylandscanner/qtwaylandscanner.cpp b/src/tools/qtwaylandscanner/qtwaylandscanner.cpp index 1b0a4a149ca..273a0012e09 100644 --- a/src/tools/qtwaylandscanner/qtwaylandscanner.cpp +++ b/src/tools/qtwaylandscanner/qtwaylandscanner.cpp @@ -196,7 +196,7 @@ Scanner::WaylandEvent Scanner::readEvent(QXmlStreamReader &xml, bool request) .type = byteArrayValue(xml, "type"), .interface = byteArrayValue(xml, "interface"), .summary = byteArrayValue(xml, "summary"), - .allowNull = boolValue(xml, "allowNull"), + .allowNull = boolValue(xml, "allow-null"), }; event.arguments.push_back(std::move(argument)); } @@ -937,9 +937,12 @@ bool Scanner::process() printf(",\n"); QByteArray cType = waylandToCType(a.type, a.interface); QByteArray qtType = waylandToQtType(a.type, a.interface, e.request); - if (a.type == "string") - printf(" %s.toUtf8().constData()", a.name.constData()); - else if (a.type == "array") + if (a.type == "string") { + printf(" "); + if (a.allowNull) + printf("%s.isNull() ? nullptr : ", a.name.constData()); + printf("%s.toUtf8().constData()", a.name.constData()); + } else if (a.type == "array") printf(" &%s_data", a.name.constData()); else if (cType == qtType) printf(" %s", a.name.constData()); @@ -1225,9 +1228,12 @@ bool Scanner::process() } else { QByteArray cType = waylandToCType(a.type, a.interface); QByteArray qtType = waylandToQtType(a.type, a.interface, e.request); - if (a.type == "string") - printf(" %s.toUtf8().constData()", a.name.constData()); - else if (a.type == "array") + if (a.type == "string") { + printf(" "); + if (a.allowNull) + printf("%s.isNull() ? nullptr : ", a.name.constData()); + printf("%s.toUtf8().constData()", a.name.constData()); + } else if (a.type == "array") printf(" &%s_data", a.name.constData()); else if (cType == qtType) printf(" %s", a.name.constData());