From patchwork Thu Jun 9 16:48:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9167547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 04476607DA for ; Thu, 9 Jun 2016 17:25:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E622128047 for ; Thu, 9 Jun 2016 17:25:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DADA228356; Thu, 9 Jun 2016 17:25:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B35428047 for ; Thu, 9 Jun 2016 17:25:47 +0000 (UTC) Received: from localhost ([::1]:35999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB3iF-0004NA-4K for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Jun 2016 13:25:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB38f-0003ee-ES for qemu-devel@nongnu.org; Thu, 09 Jun 2016 12:49:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bB38Y-00021C-5N for qemu-devel@nongnu.org; Thu, 09 Jun 2016 12:49:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51128) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB38X-00020w-TL for qemu-devel@nongnu.org; Thu, 09 Jun 2016 12:48:54 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 724B4112775; Thu, 9 Jun 2016 16:48:53 +0000 (UTC) Received: from red.redhat.com (ovpn-116-88.phx2.redhat.com [10.3.116.88]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u59GmmCo016618; Thu, 9 Jun 2016 12:48:53 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 9 Jun 2016 10:48:37 -0600 Message-Id: <1465490926-28625-7-git-send-email-eblake@redhat.com> In-Reply-To: <1465490926-28625-1-git-send-email-eblake@redhat.com> References: <1465490926-28625-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 09 Jun 2016 16:48:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 06/15] string-input-visitor: Favor new visit_free() function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Michael Roth Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a polymorphic visit_free(), we no longer need string_input_visitor_cleanup(); which in turn means we no longer need to return a subtype from string_input_visitor_new() nor a public upcast function. Signed-off-by: Eric Blake --- v5: blank line after declaration v4: new patch --- include/qapi/string-input-visitor.h | 5 +---- qapi/string-input-visitor.c | 20 +++++--------------- qom/object.c | 25 +++++++++++-------------- tests/test-string-input-visitor.c | 22 +++++++--------------- tests/test-visitor-serialization.c | 6 +++--- 5 files changed, 27 insertions(+), 51 deletions(-) diff --git a/include/qapi/string-input-visitor.h b/include/qapi/string-input-visitor.h index 7b76c2b..3355134 100644 --- a/include/qapi/string-input-visitor.h +++ b/include/qapi/string-input-visitor.h @@ -22,9 +22,6 @@ typedef struct StringInputVisitor StringInputVisitor; * QAPI structs, alternates, null, or arbitrary QTypes. It also * requires a non-null list argument to visit_start_list(). */ -StringInputVisitor *string_input_visitor_new(const char *str); -void string_input_visitor_cleanup(StringInputVisitor *v); - -Visitor *string_input_get_visitor(StringInputVisitor *v); +Visitor *string_input_visitor_new(const char *str); #endif diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index abf396b..78f203c 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -330,26 +330,16 @@ static void parse_optional(Visitor *v, const char *name, bool *present) *present = true; } -Visitor *string_input_get_visitor(StringInputVisitor *v) -{ - return &v->visitor; -} - static void string_input_free(Visitor *v) { StringInputVisitor *siv = to_siv(v); - string_input_visitor_cleanup(siv); + g_list_foreach(siv->ranges, free_range, NULL); + g_list_free(siv->ranges); + g_free(siv); } -void string_input_visitor_cleanup(StringInputVisitor *v) -{ - g_list_foreach(v->ranges, free_range, NULL); - g_list_free(v->ranges); - g_free(v); -} - -StringInputVisitor *string_input_visitor_new(const char *str) +Visitor *string_input_visitor_new(const char *str) { StringInputVisitor *v; @@ -369,5 +359,5 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.free = string_input_free; v->string = str; - return v; + return &v->visitor; } diff --git a/qom/object.c b/qom/object.c index 1562f7e..00dd68c 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1216,7 +1216,7 @@ int object_property_get_enum(Object *obj, const char *name, { Error *err = NULL; StringOutputVisitor *sov; - StringInputVisitor *siv; + Visitor *v; char *str; int ret; ObjectProperty *prop = object_property_find(obj, name, errp); @@ -1243,13 +1243,12 @@ int object_property_get_enum(Object *obj, const char *name, return 0; } str = string_output_get_string(sov); - siv = string_input_visitor_new(str); string_output_visitor_cleanup(sov); - visit_type_enum(string_input_get_visitor(siv), name, &ret, - enumprop->strings, errp); + v = string_input_visitor_new(str); + visit_type_enum(v, name, &ret, enumprop->strings, errp); g_free(str); - string_input_visitor_cleanup(siv); + visit_free(v); return ret; } @@ -1259,7 +1258,7 @@ void object_property_get_uint16List(Object *obj, const char *name, { Error *err = NULL; StringOutputVisitor *ov; - StringInputVisitor *iv; + Visitor *v; char *str; ov = string_output_visitor_new(false); @@ -1270,11 +1269,11 @@ void object_property_get_uint16List(Object *obj, const char *name, goto out; } str = string_output_get_string(ov); - iv = string_input_visitor_new(str); - visit_type_uint16List(string_input_get_visitor(iv), NULL, list, errp); + v = string_input_visitor_new(str); + visit_type_uint16List(v, NULL, list, errp); g_free(str); - string_input_visitor_cleanup(iv); + visit_free(v); out: string_output_visitor_cleanup(ov); } @@ -1282,11 +1281,9 @@ out: void object_property_parse(Object *obj, const char *string, const char *name, Error **errp) { - StringInputVisitor *siv; - siv = string_input_visitor_new(string); - object_property_set(obj, string_input_get_visitor(siv), name, errp); - - string_input_visitor_cleanup(siv); + Visitor *v = string_input_visitor_new(string); + object_property_set(obj, v, name, errp); + visit_free(v); } char *object_property_print(Object *obj, const char *name, bool human, diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-visitor.c index 7fe7a9c2..d837ebe 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -20,15 +20,15 @@ #include "qapi/qmp/types.h" typedef struct TestInputVisitorData { - StringInputVisitor *siv; + Visitor *v; } TestInputVisitorData; static void visitor_input_teardown(TestInputVisitorData *data, const void *unused) { - if (data->siv) { - string_input_visitor_cleanup(data->siv); - data->siv = NULL; + if (data->v) { + visit_free(data->v); + data->v = NULL; } } @@ -39,15 +39,9 @@ static Visitor *visitor_input_test_init(TestInputVisitorData *data, const char *string) { - Visitor *v; - - data->siv = string_input_visitor_new(string); - g_assert(data->siv != NULL); - - v = string_input_get_visitor(data->siv); - g_assert(v != NULL); - - return v; + data->v = string_input_visitor_new(string); + g_assert(data->v); + return data->v; } static void test_visitor_in_int(TestInputVisitorData *data, @@ -199,8 +193,6 @@ static void test_visitor_in_enum(TestInputVisitorData *data, visitor_input_teardown(data, NULL); } - - data->siv = NULL; } /* Try to crash the visitors */ diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c index bcbfd2a..c3c8634 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -1056,7 +1056,7 @@ static void qmp_cleanup(void *datap) typedef struct StringSerializeData { char *string; StringOutputVisitor *sov; - StringInputVisitor *siv; + Visitor *siv; } StringSerializeData; static void string_serialize(void *native_in, void **datap, @@ -1076,7 +1076,7 @@ static void string_deserialize(void **native_out, void *datap, d->string = string_output_get_string(d->sov); d->siv = string_input_visitor_new(d->string); - visit(string_input_get_visitor(d->siv), native_out, errp); + visit(d->siv, native_out, errp); } static void string_cleanup(void *datap) @@ -1084,7 +1084,7 @@ static void string_cleanup(void *datap) StringSerializeData *d = datap; string_output_visitor_cleanup(d->sov); - string_input_visitor_cleanup(d->siv); + visit_free(d->siv); g_free(d->string); g_free(d); }