qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 34/36] qapi: Rip out dynamic JSON parser frontend


From: Eric Blake
Subject: [Qemu-devel] [PATCH 34/36] qapi: Rip out dynamic JSON parser frontend
Date: Wed, 30 Nov 2016 13:44:52 -0600

Except for the testsuite, there are no more callers of
qobject_from_json[fv]().  We have no need to maintain dynamic
JSON parsing just for the check-qjson test, so delete the
functions. All callers of json_parser_parse() now pass NULL
for the varargs parameter; the next patch will clean that up.

Signed-off-by: Eric Blake <address@hidden>
---
 include/qapi/qmp/qjson.h |   2 -
 qobject/qjson.c          |  29 +-----------
 tests/check-qjson.c      | 113 +----------------------------------------------
 3 files changed, 3 insertions(+), 141 deletions(-)

diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h
index aa8ddd7..8188353 100644
--- a/include/qapi/qmp/qjson.h
+++ b/include/qapi/qmp/qjson.h
@@ -18,8 +18,6 @@
 #include "qapi/qmp/qstring.h"

 QObject *qobject_from_json(const char *string);
-QObject *qobject_from_jsonf(const char *string, ...) GCC_FMT_ATTR(1, 2);
-QObject *qobject_from_jsonv(const char *string, va_list *ap) GCC_FMT_ATTR(1, 
0);

 QString *qobject_to_json(const QObject *obj);
 QString *qobject_to_json_pretty(const QObject *obj);
diff --git a/qobject/qjson.c b/qobject/qjson.c
index 4929008..f0ab6df 100644
--- a/qobject/qjson.c
+++ b/qobject/qjson.c
@@ -22,22 +22,19 @@
 typedef struct JSONParsingState
 {
     JSONMessageParser parser;
-    va_list *ap;
     QObject *result;
 } JSONParsingState;

 static void parse_json(JSONMessageParser *parser, GQueue *tokens)
 {
     JSONParsingState *s = container_of(parser, JSONParsingState, parser);
-    s->result = json_parser_parse(tokens, s->ap);
+    s->result = json_parser_parse(tokens, NULL);
 }

-QObject *qobject_from_jsonv(const char *string, va_list *ap)
+QObject *qobject_from_json(const char *string)
 {
     JSONParsingState state = {};

-    state.ap = ap;
-
     json_message_parser_init(&state.parser, parse_json);
     json_message_parser_feed(&state.parser, string, strlen(string));
     json_message_parser_flush(&state.parser);
@@ -46,28 +43,6 @@ QObject *qobject_from_jsonv(const char *string, va_list *ap)
     return state.result;
 }

-QObject *qobject_from_json(const char *string)
-{
-    return qobject_from_jsonv(string, NULL);
-}
-
-/*
- * IMPORTANT: This function aborts on error, thus it must not
- * be used with untrusted arguments.
- */
-QObject *qobject_from_jsonf(const char *string, ...)
-{
-    QObject *obj;
-    va_list ap;
-
-    va_start(ap, string);
-    obj = qobject_from_jsonv(string, &ap);
-    va_end(ap);
-
-    assert(obj != NULL);
-    return obj;
-}
-
 typedef struct ToJsonIterState
 {
     int indent;
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 0b21a22..4025182 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -57,7 +57,7 @@ static void escaped_string(void)

         g_assert(obj != NULL);
         g_assert(qobject_type(obj) == QTYPE_QSTRING);
-        
+
         str = qobject_to_qstring(obj);
         g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].decoded);

@@ -855,33 +855,6 @@ static void utf8_string(void)
     }
 }

-static void vararg_string(void)
-{
-    int i;
-    struct {
-        const char *decoded;
-    } test_cases[] = {
-        { "hello world" },
-        { "the quick brown fox jumped over the fence" },
-        {}
-    };
-
-    for (i = 0; test_cases[i].decoded; i++) {
-        QObject *obj;
-        QString *str;
-
-        obj = qobject_from_jsonf("%s", test_cases[i].decoded);
-
-        g_assert(obj != NULL);
-        g_assert(qobject_type(obj) == QTYPE_QSTRING);
-        
-        str = qobject_to_qstring(obj);
-        g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
-
-        QDECREF(str);
-    }
-}
-
 static void simple_number(void)
 {
     int i;
@@ -958,43 +931,6 @@ static void float_number(void)
     }
 }

-static void vararg_number(void)
-{
-    QObject *obj;
-    QInt *qint;
-    QFloat *qfloat;
-    int value = 0x2342;
-    long long value_ll = 0x2342342343LL;
-    double valuef = 2.323423423;
-
-    obj = qobject_from_jsonf("%d", value);
-    g_assert(obj != NULL);
-    g_assert(qobject_type(obj) == QTYPE_QINT);
-
-    qint = qobject_to_qint(obj);
-    g_assert(qint_get_int(qint) == value);
-
-    QDECREF(qint);
-
-    obj = qobject_from_jsonf("%lld", value_ll);
-    g_assert(obj != NULL);
-    g_assert(qobject_type(obj) == QTYPE_QINT);
-
-    qint = qobject_to_qint(obj);
-    g_assert(qint_get_int(qint) == value_ll);
-
-    QDECREF(qint);
-
-    obj = qobject_from_jsonf("%f", valuef);
-    g_assert(obj != NULL);
-    g_assert(qobject_type(obj) == QTYPE_QFLOAT);
-
-    qfloat = qobject_to_qfloat(obj);
-    g_assert(qfloat_get_double(qfloat) == valuef);
-
-    QDECREF(qfloat);
-}
-
 static void keyword_literal(void)
 {
     QObject *obj;
@@ -1028,25 +964,6 @@ static void keyword_literal(void)

     QDECREF(qbool);

-    obj = qobject_from_jsonf("%i", false);
-    g_assert(obj != NULL);
-    g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
-    qbool = qobject_to_qbool(obj);
-    g_assert(qbool_get_bool(qbool) == false);
-
-    QDECREF(qbool);
-
-    /* Test that non-zero values other than 1 get collapsed to true */
-    obj = qobject_from_jsonf("%i", 2);
-    g_assert(obj != NULL);
-    g_assert(qobject_type(obj) == QTYPE_QBOOL);
-
-    qbool = qobject_to_qbool(obj);
-    g_assert(qbool_get_bool(qbool) == true);
-
-    QDECREF(qbool);
-
     obj = qobject_from_json("null");
     g_assert(obj != NULL);
     g_assert(qobject_type(obj) == QTYPE_QNULL);
@@ -1386,30 +1303,6 @@ static void simple_whitespace(void)
     }
 }

-static void simple_varargs(void)
-{
-    QObject *embedded_obj;
-    QObject *obj;
-    LiteralQObject decoded = QLIT_QLIST(((LiteralQObject[]){
-            QLIT_QINT(1),
-            QLIT_QINT(2),
-            QLIT_QLIST(((LiteralQObject[]){
-                        QLIT_QINT(32),
-                        QLIT_QINT(42),
-                        {}})),
-            {}}));
-
-    embedded_obj = qobject_from_json("[32, 42]");
-    g_assert(embedded_obj != NULL);
-
-    obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
-    g_assert(obj != NULL);
-
-    g_assert(compare_litqobj_to_qobj(&decoded, obj) == 1);
-
-    qobject_decref(obj);
-}
-
 static void empty_input(void)
 {
     const char *empty = "";
@@ -1510,11 +1403,9 @@ int main(int argc, char **argv)
     g_test_add_func("/literals/string/escaped", escaped_string);
     g_test_add_func("/literals/string/utf8", utf8_string);
     g_test_add_func("/literals/string/single_quote", single_quote_string);
-    g_test_add_func("/literals/string/vararg", vararg_string);

     g_test_add_func("/literals/number/simple", simple_number);
     g_test_add_func("/literals/number/float", float_number);
-    g_test_add_func("/literals/number/vararg", vararg_number);

     g_test_add_func("/literals/keyword", keyword_literal);

@@ -1524,8 +1415,6 @@ int main(int argc, char **argv)

     g_test_add_func("/whitespace/simple_whitespace", simple_whitespace);

-    g_test_add_func("/varargs/simple_varargs", simple_varargs);
-
     g_test_add_func("/errors/empty_input", empty_input);
     g_test_add_func("/errors/unterminated/string", unterminated_string);
     g_test_add_func("/errors/unterminated/escape", unterminated_escape);
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]