From patchwork Tue Mar 1 05:14:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8462011 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 AE91E9F372 for ; Tue, 1 Mar 2016 05:21:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0117C20304 for ; Tue, 1 Mar 2016 05:21:11 +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 30442202FF for ; Tue, 1 Mar 2016 05:21:10 +0000 (UTC) Received: from localhost ([::1]:40936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aack9-0002u9-FH for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Mar 2016 00:21:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aacdt-0000HG-J9 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 00:14:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aacdr-0006PB-Qa for qemu-devel@nongnu.org; Tue, 01 Mar 2016 00:14:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38345) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aacdr-0006P7-JH for qemu-devel@nongnu.org; Tue, 01 Mar 2016 00:14:39 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 4FC48486C1; Tue, 1 Mar 2016 05:14:39 +0000 (UTC) Received: from red.redhat.com (ovpn-113-165.phx2.redhat.com [10.3.113.165]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u215EZ9Q018132; Tue, 1 Mar 2016 00:14:38 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 29 Feb 2016 22:14:20 -0700 Message-Id: <1456809272-14184-7-git-send-email-eblake@redhat.com> In-Reply-To: <1456809272-14184-1-git-send-email-eblake@redhat.com> References: <1456809272-14184-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v12 06/18] qmp-input: Refactor when list is advanced 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.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 --- 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 4bb7b21..ed54d4c 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -26,9 +26,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; @@ -76,7 +77,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 @@ -90,7 +96,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]; @@ -102,7 +109,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) { @@ -152,7 +160,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; @@ -174,6 +182,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", @@ -181,7 +190,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, @@ -190,23 +200,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; } @@ -381,7 +383,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;