qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH v12 06/18] qmp-input: Refactor when list is advanced
Date: Mon, 29 Feb 2016 22:14:20 -0700	[thread overview]
Message-ID: <1456809272-14184-7-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1456809272-14184-1-git-send-email-eblake@redhat.com>

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 <eblake@redhat.com>

---
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;
-- 
2.5.0

  parent reply	other threads:[~2016-03-01  5:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-01  5:14 [Qemu-devel] [PATCH v12 00/18] qapi visitor cleanups (post-introspection cleanups subset E) Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 01/18] qapi-visit: Add visitor.type classification Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 02/18] qapi: Guarantee NULL obj on input visitor callback error Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 03/18] qmp: Drop dead command->type Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 04/18] qmp-input: Clean up stack handling Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 05/18] qmp-input: Don't consume input when checking has_member Eric Blake
2016-03-01  5:14 ` Eric Blake [this message]
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 07/18] qapi: Document visitor interfaces, add assertions Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 08/18] tests: Add check-qnull Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 09/18] qapi: Add visit_type_null() visitor Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 10/18] qmp: Support explicit null during visits Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 11/18] spapr_drc: Expose 'null' in qom-get when there is no fdt Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 12/18] qmp: Tighten output visitor rules Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 13/18] qapi: Split visit_end_struct() into pieces Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 14/18] qapi-commands: Wrap argument visit in visit_start_struct Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 15/18] qom: Wrap prop " Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 16/18] qmp-input: Require struct push to visit members of top dict Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 17/18] qapi: Simplify semantics of visit_next_list() Eric Blake
2016-03-01  5:14 ` [Qemu-devel] [PATCH v12 18/18] qapi: Change visit_type_FOO() to no longer return partial objects Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456809272-14184-7-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).