diff options
author | Markus Armbruster <armbru@redhat.com> | 2015-04-29 15:35:05 -0600 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2015-05-11 08:59:07 -0400 |
commit | 481b002cc81ed7fc7b06e32e9d4d495d81739d14 (patch) | |
tree | 20dbf5ec82cf594cdfeefe5db655d411fb55b78d /qobject | |
parent | a7c31816288a8f20fc387d69d441413e7a8c9ff1 (diff) | |
download | qemu-481b002cc81ed7fc7b06e32e9d4d495d81739d14.zip qemu-481b002cc81ed7fc7b06e32e9d4d495d81739d14.tar.gz qemu-481b002cc81ed7fc7b06e32e9d4d495d81739d14.tar.bz2 |
qobject: Add a special null QObject
I'm going to fix the JSON parser to recognize null. The obvious
representation of JSON null as (QObject *)NULL doesn't work, because
the parser already uses it as an error value. Perhaps we should
change it to free NULL for null, but that's more than I can do right
now. Create a special null QObject instead.
The existing QDict, QList, and QString all represent something that
is a pointer in C and could therefore be associated with NULL. But
right now, all three of these sub-types are always non-null once
created, so the new null sentinel object is intentionally unrelated
to them.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'qobject')
-rw-r--r-- | qobject/Makefile.objs | 2 | ||||
-rw-r--r-- | qobject/qjson.c | 3 | ||||
-rw-r--r-- | qobject/qnull.c | 29 |
3 files changed, 33 insertions, 1 deletions
diff --git a/qobject/Makefile.objs b/qobject/Makefile.objs index c9ff59c..f7595f5 100644 --- a/qobject/Makefile.objs +++ b/qobject/Makefile.objs @@ -1,3 +1,3 @@ -util-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o +util-obj-y = qnull.o qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o util-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o util-obj-y += qerror.o diff --git a/qobject/qjson.c b/qobject/qjson.c index f2857c1..846733d 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -127,6 +127,9 @@ static void to_json_list_iter(QObject *obj, void *opaque) static void to_json(const QObject *obj, QString *str, int pretty, int indent) { switch (qobject_type(obj)) { + case QTYPE_QNULL: + qstring_append(str, "null"); + break; case QTYPE_QINT: { QInt *val = qobject_to_qint(obj); char buffer[1024]; diff --git a/qobject/qnull.c b/qobject/qnull.c new file mode 100644 index 0000000..9873e26 --- /dev/null +++ b/qobject/qnull.c @@ -0,0 +1,29 @@ +/* + * QNull + * + * Copyright (C) 2015 Red Hat, Inc. + * + * Authors: + * Markus Armbruster <armbru@redhat.com> + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 + * or later. See the COPYING.LIB file in the top-level directory. + */ + +#include "qemu-common.h" +#include "qapi/qmp/qobject.h" + +static void qnull_destroy_obj(QObject *obj) +{ + assert(0); +} + +static const QType qnull_type = { + .code = QTYPE_QNULL, + .destroy = qnull_destroy_obj, +}; + +QObject qnull_ = { + .type = &qnull_type, + .refcnt = 1, +}; |