Skip to content

Commit

Permalink
json: Make JSONToken opaque outside json-parser.c
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180823164025.12553-52-armbru@redhat.com>
  • Loading branch information
Markus Armbruster committed Aug 24, 2018
1 parent a2731e0 commit abe7c20
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
4 changes: 4 additions & 0 deletions include/qapi/qmp/json-parser.h
Expand Up @@ -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
7 changes: 0 additions & 7 deletions include/qapi/qmp/json-streamer.h
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions qobject/json-parser.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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 };
Expand Down
8 changes: 1 addition & 7 deletions qobject/json-streamer.c
Expand Up @@ -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);
Expand Down

0 comments on commit abe7c20

Please sign in to comment.