From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 02/12] qapi-dealloc: Reduce use outside of generated code
Date: Fri, 4 Mar 2016 17:45:18 +0100 [thread overview]
Message-ID: <1457109928-4881-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1457109928-4881-1-git-send-email-armbru@redhat.com>
From: Eric Blake <eblake@redhat.com>
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 <eblake@redhat.com>
Message-Id: <1456262075-3311-2-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/acpi/core.c | 11 +----------
net/net.c | 31 ++++++++++---------------------
numa.c | 9 +--------
tests/test-opts-visitor.c | 10 +---------
4 files changed, 13 insertions(+), 48 deletions(-)
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 3a14e90..3d9e5c4 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -26,7 +26,6 @@
#include "hw/nvram/fw_cfg.h"
#include "qemu/config-file.h"
#include "qapi/opts-visitor.h"
-#include "qapi/dealloc-visitor.h"
#include "qapi-visit.h"
#include "qapi-event.h"
@@ -297,15 +296,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
out:
g_free(blob);
g_strfreev(pathnames);
-
- if (hdrs != NULL) {
- QapiDeallocVisitor *dv;
-
- dv = qapi_dealloc_visitor_new();
- visit_type_AcpiTableOptions(qapi_dealloc_get_visitor(dv), NULL, &hdrs,
- NULL);
- qapi_dealloc_visitor_cleanup(dv);
- }
+ qapi_free_AcpiTableOptions(hdrs);
error_propagate(errp, err);
}
diff --git a/net/net.c b/net/net.c
index aebf753..b0c832e 100644
--- a/net/net.c
+++ b/net/net.c
@@ -42,7 +42,6 @@
#include "qemu/main-loop.h"
#include "qapi-visit.h"
#include "qapi/opts-visitor.h"
-#include "qapi/dealloc-visitor.h"
#include "sysemu/sysemu.h"
#include "net/filter.h"
#include "qapi/string-output-visitor.h"
@@ -1043,38 +1042,28 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
}
-static void net_visit(Visitor *v, int is_netdev, void **object, Error **errp)
-{
- if (is_netdev) {
- visit_type_Netdev(v, NULL, (Netdev **)object, errp);
- } else {
- visit_type_NetLegacy(v, NULL, (NetLegacy **)object, errp);
- }
-}
-
-
int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
{
void *object = NULL;
Error *err = NULL;
int ret = -1;
+ OptsVisitor *ov = opts_visitor_new(opts);
+ Visitor *v = opts_get_visitor(ov);
- {
- OptsVisitor *ov = opts_visitor_new(opts);
-
- net_visit(opts_get_visitor(ov), is_netdev, &object, &err);
- opts_visitor_cleanup(ov);
+ if (is_netdev) {
+ visit_type_Netdev(v, NULL, (Netdev **)&object, &err);
+ } else {
+ visit_type_NetLegacy(v, NULL, (NetLegacy **)&object, &err);
}
if (!err) {
ret = net_client_init1(object, is_netdev, &err);
}
- if (object) {
- QapiDeallocVisitor *dv = qapi_dealloc_visitor_new();
-
- net_visit(qapi_dealloc_get_visitor(dv), is_netdev, &object, NULL);
- qapi_dealloc_visitor_cleanup(dv);
+ if (is_netdev) {
+ qapi_free_Netdev(object);
+ } else {
+ qapi_free_NetLegacy(object);
}
error_propagate(errp, err);
diff --git a/numa.c b/numa.c
index 4c4f7f5..da27bf8 100644
--- a/numa.c
+++ b/numa.c
@@ -31,7 +31,6 @@
#include "include/exec/cpu-common.h" /* for RAM_ADDR_FMT */
#include "qapi-visit.h"
#include "qapi/opts-visitor.h"
-#include "qapi/dealloc-visitor.h"
#include "hw/boards.h"
#include "sysemu/hostmem.h"
#include "qmp-commands.h"
@@ -243,13 +242,7 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
error:
error_report_err(err);
-
- if (object) {
- QapiDeallocVisitor *dv = qapi_dealloc_visitor_new();
- visit_type_NumaOptions(qapi_dealloc_get_visitor(dv), NULL, &object,
- NULL);
- qapi_dealloc_visitor_cleanup(dv);
- }
+ qapi_free_NumaOptions(object);
return -1;
}
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);
}
--
2.4.3
next prev parent reply other threads:[~2016-03-04 16:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-04 16:45 [Qemu-devel] [PULL 00/12] QAPI patches for 2016-03-04 Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 01/12] qmp-shell: fix pretty printing of JSON responses Markus Armbruster
2016-03-04 16:45 ` Markus Armbruster [this message]
2016-03-04 16:45 ` [Qemu-devel] [PULL 03/12] qapi: Rename 'fields' to 'members' in generator Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 04/12] qapi: Rename 'fields' to 'members' in generated C code Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 05/12] qapi-visit: Expose visit_type_FOO_members() Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 06/12] qapi: Update docs to match recent generator changes Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 07/12] chardev: Shorten references into ChardevBackend Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 08/12] util: Shorten references into SocketAddress Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 09/12] ui: Shorten references into InputEvent Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 10/12] qapi: Avoid use of 'data' member of QAPI unions Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 11/12] chardev: Drop useless ChardevDummy type Markus Armbruster
2016-03-04 16:45 ` [Qemu-devel] [PULL 12/12] qapi: Drop useless 'data' member of unions Markus Armbruster
2016-03-04 17:43 ` [Qemu-devel] [PULL 00/12] QAPI patches for 2016-03-04 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457109928-4881-3-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).