%p lets you specify an already constructed qobject. It takes a weak reference.
Signed-off-by: Anthony Liguori <aligu...@us.ibm.com> --- qjson.c | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/qjson.c b/qjson.c index 9279bfb..7bedaf3 100644 --- a/qjson.c +++ b/qjson.c @@ -648,6 +648,28 @@ static QObject *parse_keyword(JSONParserContext *ctxt, const char *data, size_t return obj; } +static QObject *parse_qobject(JSONParserContext *ctxt, const char *data, size_t *length, va_list *ap) +{ + const char *ptr = data; + QObject *obj = NULL; + + ptr += parse_skip(ctxt, ptr); + + if (ap && *ptr == '%') { + ptr++; + if (*ptr == 'p') { + ptr++; + + obj = va_arg(*ap, QObject *); + qobject_incref(obj); + *length = (ptr - data); + return obj; + } + } + + return NULL; +} + static QObject *parse_value(JSONParserContext *ctxt, const char *string, size_t *length, va_list *ap) { QObject *obj; @@ -665,6 +687,9 @@ static QObject *parse_value(JSONParserContext *ctxt, const char *string, size_t if (obj == NULL) { obj = parse_keyword(ctxt, string, length); } + if (obj == NULL) { + obj = parse_qobject(ctxt, string, length, ap); + } return obj; } -- 1.6.2.5