]> git.proxmox.com Git - mirror_qemu.git/blame - qobject/qobject.c
migration: report SaveStateEntry id and name on failure
[mirror_qemu.git] / qobject / qobject.c
CommitLineData
55e1819c
EB
1/*
2 * QObject
3 *
4 * Copyright (C) 2015 Red Hat, Inc.
5 *
6 * This work is licensed under the terms of the GNU LGPL, version 2.1
7 * or later. See the COPYING.LIB file in the top-level directory.
8 */
9
f2ad72b3 10#include "qemu/osdep.h"
6b673957 11#include "qapi/qmp/qbool.h"
15280c36
MA
12#include "qapi/qmp/qnull.h"
13#include "qapi/qmp/qnum.h"
6b673957 14#include "qapi/qmp/qdict.h"
47e6b297 15#include "qapi/qmp/qlist.h"
6b673957 16#include "qapi/qmp/qstring.h"
55e1819c 17
7ee9edfd
MAL
18QEMU_BUILD_BUG_MSG(
19 offsetof(QNull, base) != 0 ||
20 offsetof(QNum, base) != 0 ||
21 offsetof(QString, base) != 0 ||
22 offsetof(QDict, base) != 0 ||
23 offsetof(QList, base) != 0 ||
24 offsetof(QBool, base) != 0,
25 "base qobject must be at offset 0");
26
7264f5c5 27static void (*qdestroy[QTYPE__MAX])(QObject *) = {
55e1819c
EB
28 [QTYPE_NONE] = NULL, /* No such object exists */
29 [QTYPE_QNULL] = NULL, /* qnull_ is indestructible */
01b2ffce 30 [QTYPE_QNUM] = qnum_destroy_obj,
55e1819c
EB
31 [QTYPE_QSTRING] = qstring_destroy_obj,
32 [QTYPE_QDICT] = qdict_destroy_obj,
33 [QTYPE_QLIST] = qlist_destroy_obj,
55e1819c
EB
34 [QTYPE_QBOOL] = qbool_destroy_obj,
35};
36
37void qobject_destroy(QObject *obj)
38{
3d3eacae
MAL
39 assert(!obj->base.refcnt);
40 assert(QTYPE_QNULL < obj->base.type && obj->base.type < QTYPE__MAX);
41 qdestroy[obj->base.type](obj);
55e1819c 42}
b38dd678
HR
43
44
45static bool (*qis_equal[QTYPE__MAX])(const QObject *, const QObject *) = {
46 [QTYPE_NONE] = NULL, /* No such object exists */
47 [QTYPE_QNULL] = qnull_is_equal,
48 [QTYPE_QNUM] = qnum_is_equal,
49 [QTYPE_QSTRING] = qstring_is_equal,
50 [QTYPE_QDICT] = qdict_is_equal,
51 [QTYPE_QLIST] = qlist_is_equal,
52 [QTYPE_QBOOL] = qbool_is_equal,
53};
54
55bool qobject_is_equal(const QObject *x, const QObject *y)
56{
57 /* We cannot test x == y because an object does not need to be
58 * equal to itself (e.g. NaN floats are not). */
59
60 if (!x && !y) {
61 return true;
62 }
63
3d3eacae 64 if (!x || !y || x->base.type != y->base.type) {
b38dd678
HR
65 return false;
66 }
67
3d3eacae 68 assert(QTYPE_NONE < x->base.type && x->base.type < QTYPE__MAX);
b38dd678 69
3d3eacae 70 return qis_equal[x->base.type](x, y);
b38dd678 71}