From abe7c2067c21a89c6fd4cf2d8ba2fa37160d1d55 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 23 Aug 2018 18:40:18 +0200 Subject: json: Make JSONToken opaque outside json-parser.c Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180823164025.12553-52-armbru@redhat.com> --- include/qapi/qmp/json-parser.h | 4 ++++ include/qapi/qmp/json-streamer.h | 7 ------- qobject/json-parser.c | 19 +++++++++++++++++++ qobject/json-streamer.c | 8 +------- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/qapi/qmp/json-parser.h b/include/qapi/qmp/json-parser.h index a34209db7a..21b23d7bec 100644 --- a/include/qapi/qmp/json-parser.h +++ b/include/qapi/qmp/json-parser.h @@ -15,7 +15,11 @@ #define QEMU_JSON_PARSER_H #include "qemu-common.h" +#include "qapi/qmp/json-lexer.h" +typedef struct JSONToken JSONToken; + +JSONToken *json_token(JSONTokenType type, int x, int y, GString *tokstr); QObject *json_parser_parse(GQueue *tokens, va_list *ap, Error **errp); #endif diff --git a/include/qapi/qmp/json-streamer.h b/include/qapi/qmp/json-streamer.h index d1d7fe2595..29950ac37c 100644 --- a/include/qapi/qmp/json-streamer.h +++ b/include/qapi/qmp/json-streamer.h @@ -16,13 +16,6 @@ #include "qapi/qmp/json-lexer.h" -typedef struct JSONToken { - int type; - int x; - int y; - char str[]; -} JSONToken; - typedef struct JSONMessageParser { void (*emit)(void *opaque, QObject *json, Error *err); diff --git a/qobject/json-parser.c b/qobject/json-parser.c index e9a9f937f3..a247875f14 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -26,6 +26,13 @@ #include "qapi/qmp/json-lexer.h" #include "qapi/qmp/json-streamer.h" +struct JSONToken { + JSONTokenType type; + int x; + int y; + char str[]; +}; + typedef struct JSONParserContext { Error *err; @@ -538,6 +545,18 @@ static QObject *parse_value(JSONParserContext *ctxt, va_list *ap) } } +JSONToken *json_token(JSONTokenType type, int x, int y, GString *tokstr) +{ + JSONToken *token = g_malloc(sizeof(JSONToken) + tokstr->len + 1); + + token->type = type; + memcpy(token->str, tokstr->str, tokstr->len); + token->str[tokstr->len] = 0; + token->x = x; + token->y = y; + return token; +} + QObject *json_parser_parse(GQueue *tokens, va_list *ap, Error **errp) { JSONParserContext ctxt = { .buf = tokens }; diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index 9210281a65..467bc29413 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -82,13 +82,7 @@ void json_message_process_token(JSONLexer *lexer, GString *input, goto out_emit; } - token = g_malloc(sizeof(JSONToken) + input->len + 1); - token->type = type; - memcpy(token->str, input->str, input->len); - token->str[input->len] = 0; - token->x = x; - token->y = y; - + token = json_token(type, x, y, input); parser->token_size += input->len; g_queue_push_tail(&parser->tokens, token); -- cgit v1.2.3