From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ5V1-0002pr-1A for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZ5V0-0005Sv-4w for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44527) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ5Uz-0005Sg-Tk for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:10 -0500 From: Eric Blake Date: Thu, 25 Feb 2016 16:38:41 -0700 Message-Id: <1456443528-13901-13-git-send-email-eblake@redhat.com> In-Reply-To: <1456443528-13901-1-git-send-email-eblake@redhat.com> References: <1456443528-13901-1-git-send-email-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 12/19] qapi: Fix command with named empty argument type List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, Michael Roth The generator special-cased { 'command':'foo', 'data': {} } to avoid emitting a visitor variable, but failed to see that { 'struct':'NamedEmptyType, 'data': {} } { 'command':'foo', 'data':'NamedEmptyType' } needs the same treatment. There, the generator happily generates a visitor to get no arguments, and a visitor to destroy no arguments; and the compiler isn't happy with that, as demonstrated by the updated qapi-schema-test.json: tests/test-qmp-marshal.c: In function =E2=80=98qmp_marshal_user_def_cmd= 0=E2=80=99: tests/test-qmp-marshal.c:264:14: error: variable =E2=80=98v=E2=80=99 se= t but not used [-Werror=3Dunused-but-set-variable] Visitor *v; ^ No change to generated code except for the testsuite addition. Signed-off-by: Eric Blake Reviewed-by: Marc-Andr=C3=A9 Lureau --- v2: no change v1: enhance commit message Previously posted as part of qapi cleanup subset E: v9: no change v8: no change v7: no change v6: new patch --- scripts/qapi-commands.py | 6 +++--- tests/test-qmp-commands.c | 5 +++++ tests/qapi-schema/qapi-schema-test.json | 2 ++ tests/qapi-schema/qapi-schema-test.out | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index f44e01f..7c9cfbf 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -65,7 +65,7 @@ def gen_marshal_vars(arg_type, ret_type): ''', c_type=3Dret_type.c_type()) - if arg_type: + if arg_type and not arg_type.is_empty(): ret +=3D mcgen(''' QmpInputVisitor *qiv =3D qmp_input_visitor_new_strict(QOBJECT(args))= ; QapiDeallocVisitor *qdv; @@ -97,7 +97,7 @@ def gen_marshal_vars(arg_type, ret_type): def gen_marshal_input_visit(arg_type, dealloc=3DFalse): ret =3D '' - if not arg_type: + if not arg_type or arg_type.is_empty(): return ret if dealloc: @@ -177,7 +177,7 @@ def gen_marshal(name, arg_type, ret_type): # 'goto out' produced by gen_marshal_input_visit->gen_visit_members(= ) # for each arg_type member, and by gen_call() for ret_type - if (arg_type and arg_type.members) or ret_type: + if (arg_type and not arg_type.is_empty()) or ret_type: ret +=3D mcgen(''' out: diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index d6171f2..650ba46 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -13,6 +13,11 @@ void qmp_user_def_cmd(Error **errp) { } +Empty2 *qmp_user_def_cmd0(Error **errp) +{ + return g_new0(Empty2, 1); +} + void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp) { } diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/= qapi-schema-test.json index b5d0c53..33e8517 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -18,6 +18,8 @@ { 'struct': 'Empty1', 'data': { } } { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } +{ 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' } + # for testing override of default naming heuristic { 'enum': 'QEnumTwo', 'prefix': 'QENUM_TWO', diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/q= api-schema-test.out index 225e2db..6b97fa5 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -203,6 +203,8 @@ command guest-sync :obj-guest-sync-arg -> any gen=3DTrue success_response=3DTrue command user_def_cmd None -> None gen=3DTrue success_response=3DTrue +command user_def_cmd0 Empty2 -> Empty2 + gen=3DTrue success_response=3DTrue command user_def_cmd1 :obj-user_def_cmd1-arg -> None gen=3DTrue success_response=3DTrue command user_def_cmd2 :obj-user_def_cmd2-arg -> UserDefTwo --=20 2.5.0