aboutsummaryrefslogtreecommitdiff
path: root/qobject/json-streamer.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2015-11-25 22:23:31 +0100
committerMarkus Armbruster <armbru@redhat.com>2015-11-26 10:07:07 +0100
commit95385fe9ace7db156b924da6b6f5c9082b68ba68 (patch)
tree88b9c1f079121615d127fe83026dbf4d3176d5f6 /qobject/json-streamer.c
parentd538b25543f4db026bb435066e2403a542522c40 (diff)
downloadqemu-95385fe9ace7db156b924da6b6f5c9082b68ba68.zip
qemu-95385fe9ace7db156b924da6b6f5c9082b68ba68.tar.gz
qemu-95385fe9ace7db156b924da6b6f5c9082b68ba68.tar.bz2
qjson: store tokens in a GQueue
Even though we still have the "streamer" concept, the tokens can now be deleted as they are read. While doing so convert from QList to GQueue, since the next step will make tokens not a QObject and we will have to do the conversion anyway. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <1448300659-23559-4-git-send-email-pbonzini@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'qobject/json-streamer.c')
-rw-r--r--qobject/json-streamer.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c
index 7292f3a..f7a3e78 100644
--- a/qobject/json-streamer.c
+++ b/qobject/json-streamer.c
@@ -22,6 +22,14 @@
#define MAX_TOKEN_SIZE (64ULL << 20)
#define MAX_NESTING (1ULL << 10)
+static void json_message_free_tokens(JSONMessageParser *parser)
+{
+ if (parser->tokens) {
+ g_queue_free(parser->tokens);
+ parser->tokens = NULL;
+ }
+}
+
static void json_message_process_token(JSONLexer *lexer, GString *input,
JSONTokenType type, int x, int y)
{
@@ -53,7 +61,7 @@ static void json_message_process_token(JSONLexer *lexer, GString *input,
parser->token_size += input->len;
- qlist_append(parser->tokens, dict);
+ g_queue_push_tail(parser->tokens, dict);
if (type == JSON_ERROR) {
goto out_emit_bad;
@@ -77,27 +85,24 @@ out_emit_bad:
* Clear out token list and tell the parser to emit an error
* indication by passing it a NULL list
*/
- QDECREF(parser->tokens);
- parser->tokens = NULL;
+ json_message_free_tokens(parser);
out_emit:
/* send current list of tokens to parser and reset tokenizer */
parser->brace_count = 0;
parser->bracket_count = 0;
+ /* parser->emit takes ownership of parser->tokens. */
parser->emit(parser, parser->tokens);
- if (parser->tokens) {
- QDECREF(parser->tokens);
- }
- parser->tokens = qlist_new();
+ parser->tokens = g_queue_new();
parser->token_size = 0;
}
void json_message_parser_init(JSONMessageParser *parser,
- void (*func)(JSONMessageParser *, QList *))
+ void (*func)(JSONMessageParser *, GQueue *))
{
parser->emit = func;
parser->brace_count = 0;
parser->bracket_count = 0;
- parser->tokens = qlist_new();
+ parser->tokens = g_queue_new();
parser->token_size = 0;
json_lexer_init(&parser->lexer, json_message_process_token);
@@ -117,5 +122,5 @@ int json_message_parser_flush(JSONMessageParser *parser)
void json_message_parser_destroy(JSONMessageParser *parser)
{
json_lexer_destroy(&parser->lexer);
- QDECREF(parser->tokens);
+ json_message_free_tokens(parser);
}