[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RFC 17/19] qobject: Add a special null QObject
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH RFC 17/19] qobject: Add a special null QObject |
Date: |
Thu, 2 Apr 2015 19:29:01 +0200 |
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.
Signed-off-by: Markus Armbruster <address@hidden>
---
include/qapi/qmp/qobject.h | 9 +++++++++
qobject/Makefile.objs | 2 +-
qobject/qjson.c | 3 +++
qobject/qnull.c | 29 +++++++++++++++++++++++++++++
4 files changed, 42 insertions(+), 1 deletion(-)
create mode 100644 qobject/qnull.c
diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h
index 0991296..b6d18c2 100644
--- a/include/qapi/qmp/qobject.h
+++ b/include/qapi/qmp/qobject.h
@@ -37,6 +37,7 @@
typedef enum {
QTYPE_NONE, /* sentinel value, no QObject has this type code */
+ QTYPE_QNULL,
QTYPE_QINT,
QTYPE_QSTRING,
QTYPE_QDICT,
@@ -110,4 +111,12 @@ static inline qtype_code qobject_type(const QObject *obj)
return obj->type->code;
}
+extern QObject qnull_;
+
+static inline QObject *qnull(void)
+{
+ qobject_incref(&qnull_);
+ return &qnull_;
+}
+
#endif /* QOBJECT_H */
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..58118c2
--- /dev/null
+++ b/qobject/qnull.c
@@ -0,0 +1,29 @@
+/*
+ * QNull
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * Authors:
+ * Markus Armbruster <address@hidden>
+ *
+ * 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_QINT,
+ .destroy = qnull_destroy_obj,
+};
+
+QObject qnull_ = {
+ .type = &qnull_type,
+ .refcnt = 1
+};
--
1.9.3
- Re: [Qemu-devel] [PATCH RFC 06/19] qapi: Use c_enum_const() in generate_alternate_qtypes(), (continued)
- [Qemu-devel] [PATCH RFC 07/19] qapi: Move camel_to_upper(), c_enum_const() to closely related code, Markus Armbruster, 2015/04/02
- [Qemu-devel] [PATCH RFC 12/19] qapi: Turn generators' mandatory option -i into an argument, Markus Armbruster, 2015/04/02
- [Qemu-devel] [PATCH RFC 09/19] qapi: qapi-commands.py option --type is unused, drop it, Markus Armbruster, 2015/04/02
- [Qemu-devel] [PATCH RFC 15/19] qapi: Inline gen_command_decl_prologue(), gen_command_def_prologue(), Markus Armbruster, 2015/04/02
- [Qemu-devel] [PATCH RFC 17/19] qobject: Add a special null QObject,
Markus Armbruster <=
- [Qemu-devel] [PATCH RFC 14/19] qapi: Drop pointless flush() before close(), Markus Armbruster, 2015/04/02
- [Qemu-devel] [PATCH RFC 18/19] json-parser: Fix to recognize null, Markus Armbruster, 2015/04/02
- [Qemu-devel] [PATCH RFC 19/19] qapi: New QMP command query-schema for QMP schema introspection, Markus Armbruster, 2015/04/02