34b321
From 3cf8ec8ff0ad3920ce23166b2576655bcd886c5a Mon Sep 17 00:00:00 2001
34b321
From: Markus Armbruster <armbru@redhat.com>
34b321
Date: Wed, 27 Jul 2016 07:35:05 +0200
34b321
Subject: [PATCH 07/16] qjson: Inline token_is_keyword() and simplify
34b321
34b321
RH-Author: Markus Armbruster <armbru@redhat.com>
34b321
Message-id: <1469604913-12442-9-git-send-email-armbru@redhat.com>
34b321
Patchwork-id: 71483
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 07/15] qjson: Inline token_is_keyword() and simplify
34b321
Bugzilla: 1276036
34b321
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
RH-Acked-by: John Snow <jsnow@redhat.com>
34b321
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
34b321
34b321
Signed-off-by: Markus Armbruster <armbru@redhat.com>
34b321
Message-Id: <1448486613-17634-7-git-send-email-armbru@redhat.com>
34b321
Reviewed-by: Eric Blake <eblake@redhat.com>
34b321
(cherry picked from commit 50e2a467f5315fa36c547fb6330659ba45f6bb83)
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
34b321
Conflicts:
34b321
	qobject/json-parser.c
34b321
34b321
Straighforward conflict because lacking commit fc48ffc "qobject: Use
34b321
'bool' for qbool", we still use qbool_from_int(), and we lack commit
34b321
e549e71 "json-parser: Accept 'null' in QMP".
34b321
34b321
Signed-off-by: Markus Armbruster <armbru@redhat.com>
34b321
---
34b321
 qobject/json-parser.c | 18 ++++++------------
34b321
 1 file changed, 6 insertions(+), 12 deletions(-)
34b321
34b321
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
34b321
index 50bf30c..e3690de 100644
34b321
--- a/qobject/json-parser.c
34b321
+++ b/qobject/json-parser.c
34b321
@@ -64,15 +64,6 @@ static JSONTokenType token_get_type(QObject *obj)
34b321
     return qdict_get_int(qobject_to_qdict(obj), "type");
34b321
 }
34b321
 
34b321
-static int token_is_keyword(QObject *obj, const char *value)
34b321
-{
34b321
-    if (token_get_type(obj) != JSON_KEYWORD) {
34b321
-        return 0;
34b321
-    }
34b321
-
34b321
-    return strcmp(token_get_value(obj), value) == 0;
34b321
-}
34b321
-
34b321
 static int token_is_escape(QObject *obj, const char *value)
34b321
 {
34b321
     if (token_get_type(obj) != JSON_ESCAPE) {
34b321
@@ -534,6 +525,7 @@ static QObject *parse_keyword(JSONParserContext *ctxt)
34b321
 {
34b321
     QObject *token, *ret;
34b321
     JSONParserContext saved_ctxt = parser_context_save(ctxt);
34b321
+    const char *val;
34b321
 
34b321
     token = parser_context_pop_token(ctxt);
34b321
     if (token == NULL) {
34b321
@@ -544,12 +536,14 @@ static QObject *parse_keyword(JSONParserContext *ctxt)
34b321
         goto out;
34b321
     }
34b321
 
34b321
-    if (token_is_keyword(token, "true")) {
34b321
+    val = token_get_value(token);
34b321
+
34b321
+    if (!strcmp(val, "true")) {
34b321
         ret = QOBJECT(qbool_from_int(true));
34b321
-    } else if (token_is_keyword(token, "false")) {
34b321
+    } else if (!strcmp(val, "false")) {
34b321
         ret = QOBJECT(qbool_from_int(false));
34b321
     } else {
34b321
-        parse_error(ctxt, token, "invalid keyword `%s'", token_get_value(token));
34b321
+        parse_error(ctxt, token, "invalid keyword '%s'", val);
34b321
         goto out;
34b321
     }
34b321
 
34b321
-- 
34b321
1.8.3.1
34b321