From patchwork Fri Apr 8 16:13:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8784541 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 15D149F659 for ; Fri, 8 Apr 2016 16:15:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5D2C8202DD for ; Fri, 8 Apr 2016 16:15:55 +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 89FE12011D for ; Fri, 8 Apr 2016 16:15:54 +0000 (UTC) Received: from localhost ([::1]:57032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoZ4b-0003yc-Pv for patchwork-qemu-devel@patchwork.kernel.org; Fri, 08 Apr 2016 12:15:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoZ28-0007gL-8p for qemu-devel@nongnu.org; Fri, 08 Apr 2016 12:13:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aoZ26-0002M8-E2 for qemu-devel@nongnu.org; Fri, 08 Apr 2016 12:13:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoZ26-0002Lt-6c for qemu-devel@nongnu.org; Fri, 08 Apr 2016 12:13:18 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 CEE03C0467E4; Fri, 8 Apr 2016 16:13:17 +0000 (UTC) Received: from red.redhat.com (ovpn-113-199.phx2.redhat.com [10.3.113.199]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u38GDEGJ012676; Fri, 8 Apr 2016 12:13:17 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 8 Apr 2016 10:13:00 -0600 Message-Id: <1460131992-32278-8-git-send-email-eblake@redhat.com> In-Reply-To: <1460131992-32278-1-git-send-email-eblake@redhat.com> References: <1460131992-32278-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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 v14 07/19] qmp-input: Refactor when list is advanced 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, Michael Roth Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 Refactor the code to advance the QListEntry pointer at the point where visit_type_FOO() is called, rather than visit_next_list(). This will allow a future patch to move the visit of the list head into visit_start_list(), and get rid of the 'first' flag. Signed-off-by: Eric Blake --- v14: no change v13: no change v12: new patch --- qapi/qmp-input-visitor.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index cfaf378..1820360 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -27,9 +27,10 @@ typedef struct StackObject { QObject *obj; /* Object being visited */ - /* If obj is list: NULL if list is at head, otherwise tail of list - * still needing visits */ + /* If obj is list: tail of list still needing visits */ const QListEntry *entry; + /* If obj is list: true if head is not visited yet */ + bool first; GHashTable *h; /* If obj is dict: remaining keys needing visits */ } StackObject; @@ -77,7 +78,12 @@ static QObject *qmp_input_get_object(QmpInputVisitor *qiv, * of the list. */ if (tos->entry) { assert(qobject_type(qobj) == QTYPE_QLIST); - return qlist_entry_obj(tos->entry); + assert(!tos->first); + qobj = qlist_entry_obj(tos->entry); + if (consume) { + tos->entry = qlist_next(tos->entry); + } + return qobj; } /* Otherwise, we are at the root of the visit or the start of a @@ -91,7 +97,8 @@ static void qdict_add_key(const char *key, QObject *obj, void *opaque) g_hash_table_insert(h, (gpointer) key, NULL); } -static void qmp_input_push(QmpInputVisitor *qiv, QObject *obj, Error **errp) +static void qmp_input_push(QmpInputVisitor *qiv, QObject *obj, + const QListEntry *entry, Error **errp) { GHashTable *h; StackObject *tos = &qiv->stack[qiv->nb_stack]; @@ -103,7 +110,8 @@ static void qmp_input_push(QmpInputVisitor *qiv, QObject *obj, Error **errp) } tos->obj = obj; - tos->entry = NULL; + tos->entry = entry; + tos->first = true; tos->h = NULL; if (qiv->strict && qobject_type(obj) == QTYPE_QDICT) { @@ -153,7 +161,7 @@ static void qmp_input_start_struct(Visitor *v, const char *name, void **obj, return; } - qmp_input_push(qiv, qobj, &err); + qmp_input_push(qiv, qobj, NULL, &err); if (err) { error_propagate(errp, err); return; @@ -175,6 +183,7 @@ static void qmp_input_start_list(Visitor *v, const char *name, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, true); + const QListEntry *entry; if (!qobj || qobject_type(qobj) != QTYPE_QLIST) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", @@ -182,7 +191,8 @@ static void qmp_input_start_list(Visitor *v, const char *name, Error **errp) return; } - qmp_input_push(qiv, qobj, errp); + entry = qlist_first(qobject_to_qlist(qobj)); + qmp_input_push(qiv, qobj, entry, errp); } static GenericList *qmp_input_next_list(Visitor *v, GenericList **list, @@ -191,23 +201,15 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList **list, QmpInputVisitor *qiv = to_qiv(v); GenericList *entry; StackObject *so = &qiv->stack[qiv->nb_stack - 1]; - bool first; - if (so->entry == NULL) { - so->entry = qlist_first(qobject_to_qlist(so->obj)); - first = true; - } else { - so->entry = qlist_next(so->entry); - first = false; - } - - if (so->entry == NULL) { + if (!so->entry) { return NULL; } entry = g_malloc0(size); - if (first) { + if (so->first) { *list = entry; + so->first = false; } else { (*list)->next = entry; } @@ -382,7 +384,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj) v->visitor.type_any = qmp_input_type_any; v->visitor.optional = qmp_input_optional; - qmp_input_push(v, obj, NULL); + qmp_input_push(v, obj, NULL, NULL); qobject_incref(obj); return v;