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.

Backports commit 481b002cc81ed7fc7b06e32e9d4d495d81739d14 from qemu
This commit is contained in:
Markus Armbruster 2018-02-19 21:22:11 -05:00 committed by Lioncash
parent 0ae71ac202
commit 105a6be9b0
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
7 changed files with 48 additions and 2 deletions

View file

@ -211,6 +211,7 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\
<ClCompile Include="..\..\..\qemu\qobject\qfloat.c" />
<ClCompile Include="..\..\..\qemu\qobject\qint.c" />
<ClCompile Include="..\..\..\qemu\qobject\qlist.c" />
<ClCompile Include="..\..\..\qemu\qobject\qnull.c" />
<ClCompile Include="..\..\..\qemu\qobject\qstring.c" />
<ClCompile Include="..\..\..\qemu\qom\container.c" />
<ClCompile Include="..\..\..\qemu\qom\cpu.c" />

View file

@ -98,6 +98,9 @@
<ClCompile Include="..\..\..\qemu\qobject\qlist.c">
<Filter>qemu\qobject</Filter>
</ClCompile>
<ClCompile Include="..\..\..\qemu\qobject\qnull.c">
<Filter>qemu\qobject</Filter>
</ClCompile>
<ClCompile Include="..\..\..\qemu\qobject\qstring.c">
<Filter>qemu\qobject</Filter>
</ClCompile>

View file

@ -39,6 +39,7 @@
<ClCompile Include="..\..\..\qemu\qobject\qfloat.c" />
<ClCompile Include="..\..\..\qemu\qobject\qint.c" />
<ClCompile Include="..\..\..\qemu\qobject\qlist.c" />
<ClCompile Include="..\..\..\qemu\qobject\qnull.c" />
<ClCompile Include="..\..\..\qemu\qobject\qstring.c" />
<ClCompile Include="..\..\..\qemu\qom\container.c" />
<ClCompile Include="..\..\..\qemu\qom\cpu.c" />

View file

@ -132,6 +132,9 @@
<ClCompile Include="..\..\..\qemu\qobject\qlist.c">
<Filter>qemu\qobject</Filter>
</ClCompile>
<ClCompile Include="..\..\..\qemu\qobject\qnull.c">
<Filter>qemu\qobject</Filter>
</ClCompile>
<ClCompile Include="..\..\..\qemu\qobject\qstring.c">
<Filter>qemu\qobject</Filter>
</ClCompile>

View file

@ -3,7 +3,7 @@
*
* Based on ideas by Avi Kivity <avi@redhat.com>
*
* Copyright (C) 2009 Red Hat Inc.
* Copyright (C) 2009, 2015 Red Hat Inc.
*
* Authors:
* Luiz Capitulino <lcapitulino@redhat.com>
@ -37,6 +37,7 @@
typedef enum {
QTYPE_NONE,
QTYPE_QNULL,
QTYPE_QINT,
QTYPE_QSTRING,
QTYPE_QDICT,
@ -111,4 +112,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 */

View file

@ -1 +1 @@
util-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
util-obj-y = qint.o qnull.o qstring.o qdict.o qlist.o qfloat.o qbool.o

29
qemu/qobject/qnull.c Normal file
View file

@ -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 = {
QTYPE_QNULL,
qnull_destroy_obj,
};
QObject qnull_ = {
&qnull_type,
1,
};