1
2
3
4
5
6
7
8
9
10#include "qemu/osdep.h"
11#include "qapi/qmp/qbool.h"
12#include "qapi/qmp/qnull.h"
13#include "qapi/qmp/qnum.h"
14#include "qapi/qmp/qdict.h"
15#include "qapi/qmp/qlist.h"
16#include "qapi/qmp/qstring.h"
17#include "qobject-internal.h"
18
19QEMU_BUILD_BUG_MSG(
20 offsetof(QNull, base) != 0 ||
21 offsetof(QNum, base) != 0 ||
22 offsetof(QString, base) != 0 ||
23 offsetof(QDict, base) != 0 ||
24 offsetof(QList, base) != 0 ||
25 offsetof(QBool, base) != 0,
26 "base qobject must be at offset 0");
27
28static void (*qdestroy[QTYPE__MAX])(QObject *) = {
29 [QTYPE_NONE] = NULL,
30 [QTYPE_QNULL] = NULL,
31 [QTYPE_QNUM] = qnum_destroy_obj,
32 [QTYPE_QSTRING] = qstring_destroy_obj,
33 [QTYPE_QDICT] = qdict_destroy_obj,
34 [QTYPE_QLIST] = qlist_destroy_obj,
35 [QTYPE_QBOOL] = qbool_destroy_obj,
36};
37
38void qobject_destroy(QObject *obj)
39{
40 assert(!obj->base.refcnt);
41 assert(QTYPE_QNULL < obj->base.type && obj->base.type < QTYPE__MAX);
42 qdestroy[obj->base.type](obj);
43}
44
45
46static bool (*qis_equal[QTYPE__MAX])(const QObject *, const QObject *) = {
47 [QTYPE_NONE] = NULL,
48 [QTYPE_QNULL] = qnull_is_equal,
49 [QTYPE_QNUM] = qnum_is_equal,
50 [QTYPE_QSTRING] = qstring_is_equal,
51 [QTYPE_QDICT] = qdict_is_equal,
52 [QTYPE_QLIST] = qlist_is_equal,
53 [QTYPE_QBOOL] = qbool_is_equal,
54};
55
56bool qobject_is_equal(const QObject *x, const QObject *y)
57{
58
59
60
61 if (!x && !y) {
62 return true;
63 }
64
65 if (!x || !y || x->base.type != y->base.type) {
66 return false;
67 }
68
69 assert(QTYPE_NONE < x->base.type && x->base.type < QTYPE__MAX);
70
71 return qis_equal[x->base.type](x, y);
72}
73