From patchwork Tue Feb 23 21:14:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8396451 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0E964C0553 for ; Tue, 23 Feb 2016 21:29:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 38C00202AE for ; Tue, 23 Feb 2016 21:29:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5F41E20251 for ; Tue, 23 Feb 2016 21:29:46 +0000 (UTC) Received: from localhost ([::1]:60091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYKWf-0000PK-PR for patchwork-qemu-devel@patchwork.kernel.org; Tue, 23 Feb 2016 16:29:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYKIB-0001B9-0w for qemu-devel@nongnu.org; Tue, 23 Feb 2016 16:14:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYKI7-0001hG-FL for qemu-devel@nongnu.org; Tue, 23 Feb 2016 16:14:46 -0500 Received: from resqmta-po-11v.sys.comcast.net ([2001:558:fe16:19:96:114:154:170]:37151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYKI7-0001gt-0N for qemu-devel@nongnu.org; Tue, 23 Feb 2016 16:14:43 -0500 Received: from resomta-po-11v.sys.comcast.net ([96.114.154.235]) by resqmta-po-11v.sys.comcast.net with comcast id MxEP1s00654zqzk01xEi1r; Tue, 23 Feb 2016 21:14:42 +0000 Received: from red.redhat.com ([24.10.254.122]) by resomta-po-11v.sys.comcast.net with comcast id MxEe1s0062fD5rL01xEi76; Tue, 23 Feb 2016 21:14:42 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 23 Feb 2016 14:14:33 -0700 Message-Id: <1456262075-3311-2-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456262075-3311-1-git-send-email-eblake@redhat.com> References: <1456262075-3311-1-git-send-email-eblake@redhat.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1456262082; bh=Q5miT4ue8R7mXadapitAHNAJVoTPpjbmYiZzVcUFvYA=; h=Received:Received:From:To:Subject:Date:Message-Id; b=VPx2lQ6HcRuYC4zczokfAnD/c66R2s/xnTdNLi3jgo2uupLXfzJ+78Ebi5nTygs0Q REaj5/F5EYLqQJPEYNLqpNAtfZVq1o8XMJxB0dSX6mQCUlKn64FcfoVX509Q/llaPC sI282sKbBCLdzAag/5qemX+EtglLRZwQtNOUHGSAAFr9nMYn4wn/AswTTIX71n+2bD DbUw6xAM3xNa0xb+5E+D9Lleg/zJsuLn/TUYeCXHfOKno+Jfb2FcPB9flyxP62va1B h7yuwac09v0tzx9prgGRihK9RkZhTy48S3xw+2P4g53D3luVMTJMeSvY0OOjmmfBg3 GCOsqOEIQpVeg== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:170 Cc: Eduardo Habkost , "Michael S. Tsirkin" , Jason Wang , armbru@redhat.com, Michael Roth , Igor Mammedov Subject: [Qemu-devel] [PATCH 1/3] qapi-dealloc: Reduce use outside of generated code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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); }