From 96a1616c85ae62fc13aff85a34effb4b2477b7ce Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 23 Feb 2016 14:14:33 -0700 Subject: qapi-dealloc: Reduce use outside of generated code No need to roll our own use of the dealloc visitors when we can just directly use the qapi_free_FOO() functions that do what we want in one line. In net.c, inline net_visit() into its remaining lone caller. After this patch, test-visitor-serialization.c is the only non-generated file that needs to use a dealloc visitor, because it is testing low level aspects of the visitor interface. Signed-off-by: Eric Blake Message-Id: <1456262075-3311-2-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- tests/test-opts-visitor.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c index b7acf7d..297a02d 100644 --- a/tests/test-opts-visitor.c +++ b/tests/test-opts-visitor.c @@ -17,7 +17,6 @@ #include "qemu/option.h" /* qemu_opts_parse() */ #include "qapi/opts-visitor.h" /* opts_visitor_new() */ #include "test-qapi-visit.h" /* visit_type_UserDefOptions() */ -#include "qapi/dealloc-visitor.h" /* qapi_dealloc_visitor_new() */ static QemuOptsList userdef_opts = { .name = "userdef", @@ -55,14 +54,7 @@ setup_fixture(OptsVisitorFixture *f, gconstpointer test_data) static void teardown_fixture(OptsVisitorFixture *f, gconstpointer test_data) { - if (f->userdef != NULL) { - QapiDeallocVisitor *dv; - - dv = qapi_dealloc_visitor_new(); - visit_type_UserDefOptions(qapi_dealloc_get_visitor(dv), NULL, - &f->userdef, NULL); - qapi_dealloc_visitor_cleanup(dv); - } + qapi_free_UserDefOptions(f->userdef); error_free(f->err); } -- cgit v1.1 From 14f00c6c492488381a513c3816b15794446231a0 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 3 Mar 2016 09:16:43 -0700 Subject: qapi: Rename 'fields' to 'members' in generator C types and JSON objects don't have fields, but members. We shouldn't gratuitously invent terminology. This patch is a strict renaming of generator code internals (including testsuite comments), before later patches rename C interfaces. No change to generated code with this patch. Suggested-by: Markus Armbruster Signed-off-by: Eric Blake Message-Id: <1457021813-10704-2-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- tests/qapi-schema/qapi-schema-test.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index 632964a..728659e 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -77,7 +77,7 @@ 'base': 'UserDefZero', 'data': { 'string': 'str', 'enum1': 'QEnumTwo' } } -# this variant of UserDefFlatUnion defaults to a union that uses fields with +# this variant of UserDefFlatUnion defaults to a union that uses members with # allocated types to test corner cases in the cleanup/dealloc visitor { 'union': 'UserDefFlatUnion2', 'base': 'UserDefUnionBase2', -- cgit v1.1 From 0399293e5b9e5443b82103fa8e2c97deadef9825 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 3 Mar 2016 09:16:48 -0700 Subject: util: Shorten references into SocketAddress An upcoming patch will alter how simple unions, like SocketAddress, are laid out, which will impact all lines of the form 'addr->u.XXX' (expanding it to the longer 'addr->u.XXX.data'). For better legibility in that patch, and less need for line wrapping, it's better to use a temporary variable to reduce the effect of a layout change to just the variable initializations, rather than every reference within a SocketAddress. Also, take advantage of some C99 initialization where it makes sense (simplifying g_new0() to g_new()). Signed-off-by: Eric Blake Message-Id: <1457021813-10704-7-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- tests/test-io-channel-socket.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index 0697363..8a34056 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -1,7 +1,7 @@ /* * QEMU I/O channel sockets test * - * Copyright (c) 2015 Red Hat, Inc. + * Copyright (c) 2015-2016 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -283,14 +283,18 @@ static void test_io_channel_ipv4(bool async) SocketAddress *connect_addr = g_new0(SocketAddress, 1); listen_addr->type = SOCKET_ADDRESS_KIND_INET; - listen_addr->u.inet = g_new0(InetSocketAddress, 1); - listen_addr->u.inet->host = g_strdup("127.0.0.1"); - listen_addr->u.inet->port = NULL; /* Auto-select */ + listen_addr->u.inet = g_new(InetSocketAddress, 1); + *listen_addr->u.inet = (InetSocketAddress) { + .host = g_strdup("127.0.0.1"), + .port = NULL, /* Auto-select */ + }; connect_addr->type = SOCKET_ADDRESS_KIND_INET; - connect_addr->u.inet = g_new0(InetSocketAddress, 1); - connect_addr->u.inet->host = g_strdup("127.0.0.1"); - connect_addr->u.inet->port = NULL; /* Filled in later */ + connect_addr->u.inet = g_new(InetSocketAddress, 1); + *connect_addr->u.inet = (InetSocketAddress) { + .host = g_strdup("127.0.0.1"), + .port = NULL, /* Filled in later */ + }; test_io_channel(async, listen_addr, connect_addr, false); @@ -317,14 +321,18 @@ static void test_io_channel_ipv6(bool async) SocketAddress *connect_addr = g_new0(SocketAddress, 1); listen_addr->type = SOCKET_ADDRESS_KIND_INET; - listen_addr->u.inet = g_new0(InetSocketAddress, 1); - listen_addr->u.inet->host = g_strdup("::1"); - listen_addr->u.inet->port = NULL; /* Auto-select */ + listen_addr->u.inet = g_new(InetSocketAddress, 1); + *listen_addr->u.inet = (InetSocketAddress) { + .host = g_strdup("::1"), + .port = NULL, /* Auto-select */ + }; connect_addr->type = SOCKET_ADDRESS_KIND_INET; - connect_addr->u.inet = g_new0(InetSocketAddress, 1); - connect_addr->u.inet->host = g_strdup("::1"); - connect_addr->u.inet->port = NULL; /* Filled in later */ + connect_addr->u.inet = g_new(InetSocketAddress, 1); + *connect_addr->u.inet = (InetSocketAddress) { + .host = g_strdup("::1"), + .port = NULL, /* Filled in later */ + }; test_io_channel(async, listen_addr, connect_addr, false); -- cgit v1.1 From 48eb62a74fc2d6b0ae9e5f414304a85cfbf33066 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 3 Mar 2016 09:16:52 -0700 Subject: qapi: Drop useless 'data' member of unions We started moving away from the use of the 'void *data' member in the C union corresponding to a QAPI union back in commit 544a373; recent commits have gotten rid of other uses. Now that it is completely unused, we can remove the member itself as well as the FIXME comment. Update the testsuite to drop the negative test union-clash-data. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrange Message-Id: <1457021813-10704-11-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- tests/Makefile | 1 - tests/qapi-schema/union-clash-data.err | 0 tests/qapi-schema/union-clash-data.exit | 1 - tests/qapi-schema/union-clash-data.json | 7 ------- tests/qapi-schema/union-clash-data.out | 9 --------- 5 files changed, 18 deletions(-) delete mode 100644 tests/qapi-schema/union-clash-data.err delete mode 100644 tests/qapi-schema/union-clash-data.exit delete mode 100644 tests/qapi-schema/union-clash-data.json delete mode 100644 tests/qapi-schema/union-clash-data.out (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 04e34b5..cd4bbd4 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -358,7 +358,6 @@ qapi-schema += unicode-str.json qapi-schema += union-base-no-discriminator.json qapi-schema += union-branch-case.json qapi-schema += union-clash-branches.json -qapi-schema += union-clash-data.json qapi-schema += union-empty.json qapi-schema += union-invalid-base.json qapi-schema += union-optional-branch.json diff --git a/tests/qapi-schema/union-clash-data.err b/tests/qapi-schema/union-clash-data.err deleted file mode 100644 index e69de29..0000000 diff --git a/tests/qapi-schema/union-clash-data.exit b/tests/qapi-schema/union-clash-data.exit deleted file mode 100644 index 573541a..0000000 --- a/tests/qapi-schema/union-clash-data.exit +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/tests/qapi-schema/union-clash-data.json b/tests/qapi-schema/union-clash-data.json deleted file mode 100644 index 7308e69..0000000 --- a/tests/qapi-schema/union-clash-data.json +++ /dev/null @@ -1,7 +0,0 @@ -# Union branch 'data' -# FIXME: this parses, but then fails to compile due to a duplicate 'data' -# (one from the branch name, another as a filler to avoid an empty union). -# we should either detect the collision at parse time, or change the -# generated struct to allow this to compile. -{ 'union': 'TestUnion', - 'data': { 'data': 'int' } } diff --git a/tests/qapi-schema/union-clash-data.out b/tests/qapi-schema/union-clash-data.out deleted file mode 100644 index f5752f4..0000000 --- a/tests/qapi-schema/union-clash-data.out +++ /dev/null @@ -1,9 +0,0 @@ -object :empty -object :obj-int-wrapper - member data: int optional=False -enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool'] - prefix QTYPE -object TestUnion - member type: TestUnionKind optional=False - case data: :obj-int-wrapper -enum TestUnionKind ['data'] -- cgit v1.1