qapi: Separate type QNull from QObject
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
df95f1a298
commit
006ca09f30
@ -93,11 +93,15 @@ static inline QType qobject_type(const QObject *obj)
|
|||||||
return obj->type;
|
return obj->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern QObject qnull_;
|
typedef struct QNull {
|
||||||
|
QObject base;
|
||||||
|
} QNull;
|
||||||
|
|
||||||
static inline QObject *qnull(void)
|
extern QNull qnull_;
|
||||||
|
|
||||||
|
static inline QNull *qnull(void)
|
||||||
{
|
{
|
||||||
qobject_incref(&qnull_);
|
QINCREF(&qnull_);
|
||||||
return &qnull_;
|
return &qnull_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ static void qobject_output_type_any(Visitor *v, const char *name,
|
|||||||
static void qobject_output_type_null(Visitor *v, const char *name, Error **errp)
|
static void qobject_output_type_null(Visitor *v, const char *name, Error **errp)
|
||||||
{
|
{
|
||||||
QObjectOutputVisitor *qov = to_qov(v);
|
QObjectOutputVisitor *qov = to_qov(v);
|
||||||
qobject_output_add_obj(qov, name, qnull());
|
qobject_output_add(qov, name, qnull());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finish building, and return the root object.
|
/* Finish building, and return the root object.
|
||||||
|
@ -445,7 +445,7 @@ static QObject *parse_keyword(JSONParserContext *ctxt)
|
|||||||
} else if (!strcmp(token->str, "false")) {
|
} else if (!strcmp(token->str, "false")) {
|
||||||
return QOBJECT(qbool_from_bool(false));
|
return QOBJECT(qbool_from_bool(false));
|
||||||
} else if (!strcmp(token->str, "null")) {
|
} else if (!strcmp(token->str, "null")) {
|
||||||
return qnull();
|
return QOBJECT(qnull());
|
||||||
}
|
}
|
||||||
parse_error(ctxt, token, "invalid keyword '%s'", token->str);
|
parse_error(ctxt, token, "invalid keyword '%s'", token->str);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
#include "qemu-common.h"
|
#include "qemu-common.h"
|
||||||
#include "qapi/qmp/qobject.h"
|
#include "qapi/qmp/qobject.h"
|
||||||
|
|
||||||
QObject qnull_ = {
|
QNull qnull_ = {
|
||||||
.type = QTYPE_QNULL,
|
.base = {
|
||||||
.refcnt = 1,
|
.type = QTYPE_QNULL,
|
||||||
|
.refcnt = 1,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@ -2442,7 +2442,7 @@ static QDict *x86_cpu_static_props(void)
|
|||||||
|
|
||||||
d = qdict_new();
|
d = qdict_new();
|
||||||
for (i = 0; props[i]; i++) {
|
for (i = 0; props[i]; i++) {
|
||||||
qdict_put_obj(d, props[i], qnull());
|
qdict_put(d, props[i], qnull());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (w = 0; w < FEATURE_WORDS; w++) {
|
for (w = 0; w < FEATURE_WORDS; w++) {
|
||||||
@ -2452,7 +2452,7 @@ static QDict *x86_cpu_static_props(void)
|
|||||||
if (!fi->feat_names[bit]) {
|
if (!fi->feat_names[bit]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
qdict_put_obj(d, fi->feat_names[bit], qnull());
|
qdict_put(d, fi->feat_names[bit], qnull());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1012,7 +1012,7 @@ static void keyword_literal(void)
|
|||||||
{
|
{
|
||||||
QObject *obj;
|
QObject *obj;
|
||||||
QBool *qbool;
|
QBool *qbool;
|
||||||
QObject *null;
|
QNull *null;
|
||||||
QString *str;
|
QString *str;
|
||||||
|
|
||||||
obj = qobject_from_json("true", &error_abort);
|
obj = qobject_from_json("true", &error_abort);
|
||||||
@ -1053,10 +1053,10 @@ static void keyword_literal(void)
|
|||||||
g_assert(qobject_type(obj) == QTYPE_QNULL);
|
g_assert(qobject_type(obj) == QTYPE_QNULL);
|
||||||
|
|
||||||
null = qnull();
|
null = qnull();
|
||||||
g_assert(null == obj);
|
g_assert(QOBJECT(null) == obj);
|
||||||
|
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
qobject_decref(null);
|
QDECREF(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct LiteralQDictEntry LiteralQDictEntry;
|
typedef struct LiteralQDictEntry LiteralQDictEntry;
|
||||||
|
@ -24,14 +24,14 @@ static void qnull_ref_test(void)
|
|||||||
{
|
{
|
||||||
QObject *obj;
|
QObject *obj;
|
||||||
|
|
||||||
g_assert(qnull_.refcnt == 1);
|
g_assert(qnull_.base.refcnt == 1);
|
||||||
obj = qnull();
|
obj = QOBJECT(qnull());
|
||||||
g_assert(obj);
|
g_assert(obj);
|
||||||
g_assert(obj == &qnull_);
|
g_assert(obj == QOBJECT(&qnull_));
|
||||||
g_assert(qnull_.refcnt == 2);
|
g_assert(qnull_.base.refcnt == 2);
|
||||||
g_assert(qobject_type(obj) == QTYPE_QNULL);
|
g_assert(qobject_type(obj) == QTYPE_QNULL);
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
g_assert(qnull_.refcnt == 1);
|
g_assert(qnull_.base.refcnt == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qnull_visit_test(void)
|
static void qnull_visit_test(void)
|
||||||
@ -45,8 +45,8 @@ static void qnull_visit_test(void)
|
|||||||
* depend on layering violations to check qnull_ refcnt.
|
* depend on layering violations to check qnull_ refcnt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
g_assert(qnull_.refcnt == 1);
|
g_assert(qnull_.base.refcnt == 1);
|
||||||
obj = qnull();
|
obj = QOBJECT(qnull());
|
||||||
v = qobject_input_visitor_new(obj);
|
v = qobject_input_visitor_new(obj);
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
visit_type_null(v, NULL, &error_abort);
|
visit_type_null(v, NULL, &error_abort);
|
||||||
@ -55,11 +55,11 @@ static void qnull_visit_test(void)
|
|||||||
v = qobject_output_visitor_new(&obj);
|
v = qobject_output_visitor_new(&obj);
|
||||||
visit_type_null(v, NULL, &error_abort);
|
visit_type_null(v, NULL, &error_abort);
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
g_assert(obj == &qnull_);
|
g_assert(obj == QOBJECT(&qnull_));
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
|
|
||||||
g_assert(qnull_.refcnt == 1);
|
g_assert(qnull_.base.refcnt == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
Loading…
Reference in New Issue
Block a user