yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From adef92fecbb5d4e37e5e513954c088f9f1704418 Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Mon, 9 Sep 2013 14:28:13 +0200
218e99
Subject: [PATCH 22/38] qapi: Add consume argument to qmp_input_get_object()
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1378736903-18489-23-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 54209
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 22/32] qapi: Add consume argument to qmp_input_get_object()
218e99
Bugzilla: 1005818
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
Bugzilla: 1005818
218e99
218e99
This allows to just look at the next element without actually consuming
218e99
it.
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit e8316d7e8e8339a9ea593ba821a0aad26908c0d5)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 qapi/qmp-input-visitor.c | 19 ++++++++++---------
218e99
 1 file changed, 10 insertions(+), 9 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 qapi/qmp-input-visitor.c |   19 ++++++++++---------
218e99
 1 files changed, 10 insertions(+), 9 deletions(-)
218e99
218e99
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
218e99
index 59c5cac..70864a1 100644
218e99
--- a/qapi/qmp-input-visitor.c
218e99
+++ b/qapi/qmp-input-visitor.c
218e99
@@ -41,13 +41,14 @@ static QmpInputVisitor *to_qiv(Visitor *v)
218e99
 }
218e99
 
218e99
 static QObject *qmp_input_get_object(QmpInputVisitor *qiv,
218e99
-                                     const char *name)
218e99
+                                     const char *name,
218e99
+                                     bool consume)
218e99
 {
218e99
     QObject *qobj = qiv->stack[qiv->nb_stack - 1].obj;
218e99
 
218e99
     if (qobj) {
218e99
         if (name && qobject_type(qobj) == QTYPE_QDICT) {
218e99
-            if (qiv->stack[qiv->nb_stack - 1].h) {
218e99
+            if (qiv->stack[qiv->nb_stack - 1].h && consume) {
218e99
                 g_hash_table_remove(qiv->stack[qiv->nb_stack - 1].h, name);
218e99
             }
218e99
             return qdict_get(qobject_to_qdict(qobj), name);
218e99
@@ -117,7 +118,7 @@ static void qmp_input_start_struct(Visitor *v, void **obj, const char *kind,
218e99
                                    const char *name, size_t size, Error **errp)
218e99
 {
218e99
     QmpInputVisitor *qiv = to_qiv(v);
218e99
-    QObject *qobj = qmp_input_get_object(qiv, name);
218e99
+    QObject *qobj = qmp_input_get_object(qiv, name, true);
218e99
     Error *err = NULL;
218e99
 
218e99
     if (!qobj || qobject_type(qobj) != QTYPE_QDICT) {
218e99
@@ -159,7 +160,7 @@ static void qmp_input_end_implicit_struct(Visitor *v, Error **errp)
218e99
 static void qmp_input_start_list(Visitor *v, const char *name, Error **errp)
218e99
 {
218e99
     QmpInputVisitor *qiv = to_qiv(v);
218e99
-    QObject *qobj = qmp_input_get_object(qiv, name);
218e99
+    QObject *qobj = qmp_input_get_object(qiv, name, true);
218e99
 
218e99
     if (!qobj || qobject_type(qobj) != QTYPE_QLIST) {
218e99
         error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
218e99
@@ -211,7 +212,7 @@ static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name,
218e99
                                Error **errp)
218e99
 {
218e99
     QmpInputVisitor *qiv = to_qiv(v);
218e99
-    QObject *qobj = qmp_input_get_object(qiv, name);
218e99
+    QObject *qobj = qmp_input_get_object(qiv, name, true);
218e99
 
218e99
     if (!qobj || qobject_type(qobj) != QTYPE_QINT) {
218e99
         error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
218e99
@@ -226,7 +227,7 @@ static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name,
218e99
                                 Error **errp)
218e99
 {
218e99
     QmpInputVisitor *qiv = to_qiv(v);
218e99
-    QObject *qobj = qmp_input_get_object(qiv, name);
218e99
+    QObject *qobj = qmp_input_get_object(qiv, name, true);
218e99
 
218e99
     if (!qobj || qobject_type(qobj) != QTYPE_QBOOL) {
218e99
         error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
218e99
@@ -241,7 +242,7 @@ static void qmp_input_type_str(Visitor *v, char **obj, const char *name,
218e99
                                Error **errp)
218e99
 {
218e99
     QmpInputVisitor *qiv = to_qiv(v);
218e99
-    QObject *qobj = qmp_input_get_object(qiv, name);
218e99
+    QObject *qobj = qmp_input_get_object(qiv, name, true);
218e99
 
218e99
     if (!qobj || qobject_type(qobj) != QTYPE_QSTRING) {
218e99
         error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
218e99
@@ -256,7 +257,7 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name,
218e99
                                   Error **errp)
218e99
 {
218e99
     QmpInputVisitor *qiv = to_qiv(v);
218e99
-    QObject *qobj = qmp_input_get_object(qiv, name);
218e99
+    QObject *qobj = qmp_input_get_object(qiv, name, true);
218e99
 
218e99
     if (!qobj || (qobject_type(qobj) != QTYPE_QFLOAT &&
218e99
         qobject_type(qobj) != QTYPE_QINT)) {
218e99
@@ -276,7 +277,7 @@ static void qmp_input_start_optional(Visitor *v, bool *present,
218e99
                                      const char *name, Error **errp)
218e99
 {
218e99
     QmpInputVisitor *qiv = to_qiv(v);
218e99
-    QObject *qobj = qmp_input_get_object(qiv, name);
218e99
+    QObject *qobj = qmp_input_get_object(qiv, name, true);
218e99
 
218e99
     if (!qobj) {
218e99
         *present = false;
218e99
-- 
218e99
1.7.1
218e99