mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 20:33:54 -06:00
json-parser: propagate error from parser
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
d5ec4f27c3
commit
ef749d07e7
5 changed files with 25 additions and 7 deletions
|
@ -22,9 +22,11 @@
|
|||
#include "qbool.h"
|
||||
#include "json-parser.h"
|
||||
#include "json-lexer.h"
|
||||
#include "qerror.h"
|
||||
|
||||
typedef struct JSONParserContext
|
||||
{
|
||||
Error *err;
|
||||
} JSONParserContext;
|
||||
|
||||
#define BUG_ON(cond) assert(!(cond))
|
||||
|
@ -95,11 +97,15 @@ static void GCC_FMT_ATTR(3, 4) parse_error(JSONParserContext *ctxt,
|
|||
QObject *token, const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char message[1024];
|
||||
va_start(ap, msg);
|
||||
fprintf(stderr, "parse error: ");
|
||||
vfprintf(stderr, msg, ap);
|
||||
fprintf(stderr, "\n");
|
||||
vsnprintf(message, sizeof(message), msg, ap);
|
||||
va_end(ap);
|
||||
if (ctxt->err) {
|
||||
error_free(ctxt->err);
|
||||
ctxt->err = NULL;
|
||||
}
|
||||
error_set(&ctxt->err, QERR_JSON_PARSE_ERROR, message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -564,6 +570,11 @@ static QObject *parse_value(JSONParserContext *ctxt, QList **tokens, va_list *ap
|
|||
}
|
||||
|
||||
QObject *json_parser_parse(QList *tokens, va_list *ap)
|
||||
{
|
||||
return json_parser_parse_err(tokens, ap, NULL);
|
||||
}
|
||||
|
||||
QObject *json_parser_parse_err(QList *tokens, va_list *ap, Error **errp)
|
||||
{
|
||||
JSONParserContext ctxt = {};
|
||||
QList *working = qlist_copy(tokens);
|
||||
|
@ -573,5 +584,7 @@ QObject *json_parser_parse(QList *tokens, va_list *ap)
|
|||
|
||||
QDECREF(working);
|
||||
|
||||
error_propagate(errp, ctxt.err);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue