From patchwork Wed Jul 6 09:13:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 9215871 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 4C051607D9 for ; Wed, 6 Jul 2016 09:27:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A818287C9 for ; Wed, 6 Jul 2016 09:27:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EF9E287CE; Wed, 6 Jul 2016 09:27:30 +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 55947287C9 for ; Wed, 6 Jul 2016 09:27:29 +0000 (UTC) Received: from localhost ([::1]:60455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKj7A-0006Uo-BJ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 05:27:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKiuO-000758-5H for qemu-devel@nongnu.org; Wed, 06 Jul 2016 05:14:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKiuL-0000SD-5o for qemu-devel@nongnu.org; Wed, 06 Jul 2016 05:14:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49810) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKiuK-0000Rb-TY for qemu-devel@nongnu.org; Wed, 06 Jul 2016 05:14:13 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 92A4680082 for ; Wed, 6 Jul 2016 09:14:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u669E9GW024803 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 6 Jul 2016 05:14:11 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 858C21129C45; Wed, 6 Jul 2016 11:14:06 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 6 Jul 2016 11:13:58 +0200 Message-Id: <1467796446-25446-8-git-send-email-armbru@redhat.com> In-Reply-To: <1467796446-25446-1-git-send-email-armbru@redhat.com> References: <1467796446-25446-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 06 Jul 2016 09:14:12 +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] [PULL 07/15] qmp-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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Blake Now that we have a polymorphic visit_free(), we no longer need qmp_input_visitor_cleanup(); which in turn means we no longer need to return a subtype from qmp_input_visitor_new() nor a public upcast function. Generated code changes to qmp-marshal.c look like: |@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb | { | Error *err = NULL; | AddfdInfo *retval; |- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true); | Visitor *v; | q_obj_add_fd_arg arg = {0}; | |- v = qmp_input_get_visitor(qiv); |+ v = qmp_input_visitor_new(QOBJECT(args), true); | visit_start_struct(v, NULL, NULL, 0, &err); | if (err) { | goto out; Signed-off-by: Eric Blake Message-Id: <1465490926-28625-8-git-send-email-eblake@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- docs/qapi-code-gen.txt | 3 +-- include/qapi/qmp-input-visitor.h | 6 +----- qapi/qmp-input-visitor.c | 18 ++++-------------- qmp.c | 9 ++++----- qom/qom-qobject.c | 9 ++++----- replay/replay-input.c | 6 ++---- scripts/qapi-commands.py | 3 +-- tests/check-qnull.c | 8 ++++---- tests/test-qmp-commands.c | 8 ++++---- tests/test-qmp-input-strict.c | 12 +++--------- tests/test-qmp-input-visitor.c | 12 +++--------- tests/test-visitor-serialization.c | 6 +++--- util/qemu-sockets.c | 6 ++---- 13 files changed, 36 insertions(+), 70 deletions(-) diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt index db9d5b6..7c30762 100644 --- a/docs/qapi-code-gen.txt +++ b/docs/qapi-code-gen.txt @@ -1002,11 +1002,10 @@ Example: { Error *err = NULL; UserDefOne *retval; - QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true); Visitor *v; UserDefOneList *arg1 = NULL; - v = qmp_input_get_visitor(qiv); + v = qmp_input_visitor_new(QOBJECT(args), true); visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out; diff --git a/include/qapi/qmp-input-visitor.h b/include/qapi/qmp-input-visitor.h index b0624d8..f3ff5f3 100644 --- a/include/qapi/qmp-input-visitor.h +++ b/include/qapi/qmp-input-visitor.h @@ -25,10 +25,6 @@ typedef struct QmpInputVisitor QmpInputVisitor; * Set @strict to reject a parse that doesn't consume all keys of a * dictionary; otherwise excess input is ignored. */ -QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict); - -void qmp_input_visitor_cleanup(QmpInputVisitor *v); - -Visitor *qmp_input_get_visitor(QmpInputVisitor *v); +Visitor *qmp_input_visitor_new(QObject *obj, bool strict); #endif diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index 41b7f87..21edb39 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -373,25 +373,15 @@ static void qmp_input_optional(Visitor *v, const char *name, bool *present) *present = true; } -Visitor *qmp_input_get_visitor(QmpInputVisitor *v) -{ - return &v->visitor; -} - static void qmp_input_free(Visitor *v) { QmpInputVisitor *qiv = to_qiv(v); - qmp_input_visitor_cleanup(qiv); + qobject_decref(qiv->root); + g_free(qiv); } -void qmp_input_visitor_cleanup(QmpInputVisitor *v) -{ - qobject_decref(v->root); - g_free(v); -} - -QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict) +Visitor *qmp_input_visitor_new(QObject *obj, bool strict) { QmpInputVisitor *v; @@ -419,5 +409,5 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict) v->root = obj; qobject_incref(obj); - return v; + return &v->visitor; } diff --git a/qmp.c b/qmp.c index 7df6543..b6d531e 100644 --- a/qmp.c +++ b/qmp.c @@ -655,7 +655,7 @@ void qmp_object_add(const char *type, const char *id, bool has_props, QObject *props, Error **errp) { const QDict *pdict = NULL; - QmpInputVisitor *qiv; + Visitor *v; Object *obj; if (props) { @@ -666,10 +666,9 @@ void qmp_object_add(const char *type, const char *id, } } - qiv = qmp_input_visitor_new(props, true); - obj = user_creatable_add_type(type, id, pdict, - qmp_input_get_visitor(qiv), errp); - qmp_input_visitor_cleanup(qiv); + v = qmp_input_visitor_new(props, true); + obj = user_creatable_add_type(type, id, pdict, v, errp); + visit_free(v); if (obj) { object_unref(obj); } diff --git a/qom/qom-qobject.c b/qom/qom-qobject.c index b66088d..c3c9188 100644 --- a/qom/qom-qobject.c +++ b/qom/qom-qobject.c @@ -21,12 +21,11 @@ void object_property_set_qobject(Object *obj, QObject *value, const char *name, Error **errp) { - QmpInputVisitor *qiv; + Visitor *v; /* TODO: Should we reject, rather than ignore, excess input? */ - qiv = qmp_input_visitor_new(value, false); - object_property_set(obj, qmp_input_get_visitor(qiv), name, errp); - - qmp_input_visitor_cleanup(qiv); + v = qmp_input_visitor_new(value, false); + object_property_set(obj, v, name, errp); + visit_free(v); } QObject *object_property_get_qobject(Object *obj, const char *name, diff --git a/replay/replay-input.c b/replay/replay-input.c index 03e99d5..7b6fa93 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -23,7 +23,6 @@ static InputEvent *qapi_clone_InputEvent(InputEvent *src) { QmpOutputVisitor *qov; - QmpInputVisitor *qiv; Visitor *ov, *iv; QObject *obj; InputEvent *dst = NULL; @@ -37,10 +36,9 @@ static InputEvent *qapi_clone_InputEvent(InputEvent *src) return NULL; } - qiv = qmp_input_visitor_new(obj, true); - iv = qmp_input_get_visitor(qiv); + iv = qmp_input_visitor_new(obj, true); visit_type_InputEvent(iv, NULL, &dst, &error_abort); - qmp_input_visitor_cleanup(qiv); + visit_free(iv); qobject_decref(obj); return dst; diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 77ecd47..49d4ce2 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -113,11 +113,10 @@ def gen_marshal(name, arg_type, ret_type): if arg_type and arg_type.members: ret += mcgen(''' - QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true); Visitor *v; %(c_name)s arg = {0}; - v = qmp_input_get_visitor(qiv); + v = qmp_input_visitor_new(QOBJECT(args), true); visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out; diff --git a/tests/check-qnull.c b/tests/check-qnull.c index 05d562d..d0412e4 100644 --- a/tests/check-qnull.c +++ b/tests/check-qnull.c @@ -38,7 +38,7 @@ static void qnull_visit_test(void) { QObject *obj; QmpOutputVisitor *qov; - QmpInputVisitor *qiv; + Visitor *v; /* * Most tests of interactions between QObject and visitors are in @@ -48,10 +48,10 @@ static void qnull_visit_test(void) g_assert(qnull_.refcnt == 1); obj = qnull(); - qiv = qmp_input_visitor_new(obj, true); + v = qmp_input_visitor_new(obj, true); qobject_decref(obj); - visit_type_null(qmp_input_get_visitor(qiv), NULL, &error_abort); - qmp_input_visitor_cleanup(qiv); + visit_type_null(v, NULL, &error_abort); + visit_free(v); qov = qmp_output_visitor_new(); visit_type_null(qmp_output_get_visitor(qov), NULL, &error_abort); diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index e8f619d..8ffeb04 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -216,14 +216,14 @@ static void test_dealloc_partial(void) /* create partial object */ { QDict *ud2_dict; - QmpInputVisitor *qiv; + Visitor *v; ud2_dict = qdict_new(); qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text))); - qiv = qmp_input_visitor_new(QOBJECT(ud2_dict), true); - visit_type_UserDefTwo(qmp_input_get_visitor(qiv), NULL, &ud2, &err); - qmp_input_visitor_cleanup(qiv); + v = qmp_input_visitor_new(QOBJECT(ud2_dict), true); + visit_type_UserDefTwo(v, NULL, &ud2, &err); + visit_free(v); QDECREF(ud2_dict); } diff --git a/tests/test-qmp-input-strict.c b/tests/test-qmp-input-strict.c index 79739e9..814550a 100644 --- a/tests/test-qmp-input-strict.c +++ b/tests/test-qmp-input-strict.c @@ -26,7 +26,7 @@ typedef struct TestInputVisitorData { QObject *obj; - QmpInputVisitor *qiv; + Visitor *qiv; } TestInputVisitorData; static void validate_teardown(TestInputVisitorData *data, @@ -36,7 +36,7 @@ static void validate_teardown(TestInputVisitorData *data, data->obj = NULL; if (data->qiv) { - qmp_input_visitor_cleanup(data->qiv); + visit_free(data->qiv); data->qiv = NULL; } } @@ -48,8 +48,6 @@ static Visitor *validate_test_init_internal(TestInputVisitorData *data, const char *json_string, va_list *ap) { - Visitor *v; - validate_teardown(data, NULL); data->obj = qobject_from_jsonv(json_string, ap); @@ -57,11 +55,7 @@ static Visitor *validate_test_init_internal(TestInputVisitorData *data, data->qiv = qmp_input_visitor_new(data->obj, true); g_assert(data->qiv); - - v = qmp_input_get_visitor(data->qiv); - g_assert(v); - - return v; + return data->qiv; } static GCC_FMT_ATTR(2, 3) diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c index b236183..f583dce 100644 --- a/tests/test-qmp-input-visitor.c +++ b/tests/test-qmp-input-visitor.c @@ -22,7 +22,7 @@ typedef struct TestInputVisitorData { QObject *obj; - QmpInputVisitor *qiv; + Visitor *qiv; } TestInputVisitorData; static void visitor_input_teardown(TestInputVisitorData *data, @@ -32,7 +32,7 @@ static void visitor_input_teardown(TestInputVisitorData *data, data->obj = NULL; if (data->qiv) { - qmp_input_visitor_cleanup(data->qiv); + visit_free(data->qiv); data->qiv = NULL; } } @@ -44,8 +44,6 @@ static Visitor *visitor_input_test_init_internal(TestInputVisitorData *data, const char *json_string, va_list *ap) { - Visitor *v; - visitor_input_teardown(data, NULL); data->obj = qobject_from_jsonv(json_string, ap); @@ -53,11 +51,7 @@ static Visitor *visitor_input_test_init_internal(TestInputVisitorData *data, data->qiv = qmp_input_visitor_new(data->obj, false); g_assert(data->qiv); - - v = qmp_input_get_visitor(data->qiv); - g_assert(v); - - return v; + return data->qiv; } static GCC_FMT_ATTR(2, 3) diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c index c3c8634..0766dcc 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -1013,7 +1013,7 @@ static PrimitiveType pt_values[] = { typedef struct QmpSerializeData { QmpOutputVisitor *qov; - QmpInputVisitor *qiv; + Visitor *qiv; } QmpSerializeData; static void qmp_serialize(void *native_in, void **datap, @@ -1041,14 +1041,14 @@ static void qmp_deserialize(void **native_out, void *datap, d->qiv = qmp_input_visitor_new(obj, true); qobject_decref(obj_orig); qobject_decref(obj); - visit(qmp_input_get_visitor(d->qiv), native_out, errp); + visit(d->qiv, native_out, errp); } static void qmp_cleanup(void *datap) { QmpSerializeData *d = datap; qmp_output_visitor_cleanup(d->qov); - qmp_input_visitor_cleanup(d->qiv); + visit_free(d->qiv); g_free(d); } diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index cc2b043..3677cd2 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1148,7 +1148,6 @@ void qapi_copy_SocketAddress(SocketAddress **p_dest, SocketAddress *src) { QmpOutputVisitor *qov; - QmpInputVisitor *qiv; Visitor *ov, *iv; QObject *obj; @@ -1163,10 +1162,9 @@ void qapi_copy_SocketAddress(SocketAddress **p_dest, return; } - qiv = qmp_input_visitor_new(obj, true); - iv = qmp_input_get_visitor(qiv); + iv = qmp_input_visitor_new(obj, true); visit_type_SocketAddress(iv, NULL, p_dest, &error_abort); - qmp_input_visitor_cleanup(qiv); + visit_free(iv); qobject_decref(obj); }