json-parser: constify JSONToken
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo Bonzini committed
Feb 10, 2026 at 09:32 UTC
877820be501c72665aff1af468fab87f17995044
1 file changed
+12
-11
qobject/json-parser.c
+12
-11
@@ -55,7 +55,8 @@ static QObject *parse_value(JSONParserContext *ctxt);
55
* Error handler
56
*/
57
static void G_GNUC_PRINTF(3, 4) parse_error(JSONParserContext *ctxt,
58
- JSONToken *token, const char *msg, ...)
58
+ const JSONToken *token,
59
+ const char *msg, ...)
60
{
61
va_list ap;
62
char message[1024];
@@ -126,7 +127,7 @@ static int cvt4hex(const char *s)
127
* - Invalid Unicode characters are rejected.
128
* - Control characters \x00..\x1F are rejected by the lexer.
129
*/
129
-static QString *parse_string(JSONParserContext *ctxt, JSONToken *token)
130
+static QString *parse_string(JSONParserContext *ctxt, const JSONToken *token)
131
{
132
const char *ptr = token->str;
133
GString *str;
@@ -239,14 +240,14 @@ out:
240
* parser_context_pop_token is deleted as soon as parser_context_pop_token
241
* is called again.
242
*/
242
-static JSONToken *parser_context_pop_token(JSONParserContext *ctxt)
243
+static const JSONToken *parser_context_pop_token(JSONParserContext *ctxt)
244
{
245
g_free(ctxt->current);
246
ctxt->current = g_queue_pop_head(ctxt->buf);
247
return ctxt->current;
248
}
249
249
-static JSONToken *parser_context_peek_token(JSONParserContext *ctxt)
250
+static const JSONToken *parser_context_peek_token(JSONParserContext *ctxt)
251
{
252
return g_queue_peek_head(ctxt->buf);
253
}
@@ -259,7 +260,7 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict)
260
QObject *key_obj = NULL;
261
QString *key;
262
QObject *value;
262
- JSONToken *peek, *token;
263
+ const JSONToken *peek, *token;
264
265
peek = parser_context_peek_token(ctxt);
266
if (peek == NULL) {
@@ -309,7 +310,7 @@ out:
310
static QObject *parse_object(JSONParserContext *ctxt)
311
{
312
QDict *dict = NULL;
312
- JSONToken *token, *peek;
313
+ const JSONToken *token, *peek;
314
315
token = parser_context_pop_token(ctxt);
316
assert(token && token->type == JSON_LCURLY);
@@ -363,7 +364,7 @@ out:
364
static QObject *parse_array(JSONParserContext *ctxt)
365
{
366
QList *list = NULL;
366
- JSONToken *token, *peek;
367
+ const JSONToken *token, *peek;
368
369
token = parser_context_pop_token(ctxt);
370
assert(token && token->type == JSON_LSQUARE);
@@ -426,7 +427,7 @@ out:
427
428
static QObject *parse_keyword(JSONParserContext *ctxt)
429
{
429
- JSONToken *token;
430
+ const JSONToken *token;
431
432
token = parser_context_pop_token(ctxt);
433
assert(token && token->type == JSON_KEYWORD);
@@ -444,7 +445,7 @@ static QObject *parse_keyword(JSONParserContext *ctxt)
445
446
static QObject *parse_interpolation(JSONParserContext *ctxt)
447
{
447
- JSONToken *token;
448
+ const JSONToken *token;
449
450
token = parser_context_pop_token(ctxt);
451
assert(token && token->type == JSON_INTERP);
@@ -480,7 +481,7 @@ static QObject *parse_interpolation(JSONParserContext *ctxt)
481
482
static QObject *parse_literal(JSONParserContext *ctxt)
483
{
483
- JSONToken *token;
484
+ const JSONToken *token;
485
486
token = parser_context_pop_token(ctxt);
487
assert(token);
@@ -532,7 +533,7 @@ static QObject *parse_literal(JSONParserContext *ctxt)
533
534
static QObject *parse_value(JSONParserContext *ctxt)
535
{
535
- JSONToken *token;
536
+ const JSONToken *token;
537
538
token = parser_context_peek_token(ctxt);
539
if (token == NULL) {