summaryrefslogtreecommitdiff
path: root/include/qapi
diff options
context:
space:
mode:
Diffstat (limited to 'include/qapi')
-rw-r--r--include/qapi/qmp/qbool.h2
-rw-r--r--include/qapi/qmp/qdict.h2
-rw-r--r--include/qapi/qmp/qlist.h2
-rw-r--r--include/qapi/qmp/qnull.h2
-rw-r--r--include/qapi/qmp/qnum.h2
-rw-r--r--include/qapi/qmp/qobject.h31
-rw-r--r--include/qapi/qmp/qstring.h2
7 files changed, 26 insertions, 17 deletions
diff --git a/include/qapi/qmp/qbool.h b/include/qapi/qmp/qbool.h
index b9a44a1bfe..5f61e38e64 100644
--- a/include/qapi/qmp/qbool.h
+++ b/include/qapi/qmp/qbool.h
@@ -17,7 +17,7 @@
#include "qapi/qmp/qobject.h"
struct QBool {
- QObject base;
+ struct QObjectBase_ base;
bool value;
};
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index 2cc3e906f7..921a28d2d3 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -25,7 +25,7 @@ typedef struct QDictEntry {
} QDictEntry;
struct QDict {
- QObject base;
+ struct QObjectBase_ base;
size_t size;
QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX];
};
diff --git a/include/qapi/qmp/qlist.h b/include/qapi/qmp/qlist.h
index 5c673acb06..8d2c32ca28 100644
--- a/include/qapi/qmp/qlist.h
+++ b/include/qapi/qmp/qlist.h
@@ -22,7 +22,7 @@ typedef struct QListEntry {
} QListEntry;
struct QList {
- QObject base;
+ struct QObjectBase_ base;
QTAILQ_HEAD(,QListEntry) head;
};
diff --git a/include/qapi/qmp/qnull.h b/include/qapi/qmp/qnull.h
index c992ee2ae1..e8ea2c315a 100644
--- a/include/qapi/qmp/qnull.h
+++ b/include/qapi/qmp/qnull.h
@@ -16,7 +16,7 @@
#include "qapi/qmp/qobject.h"
struct QNull {
- QObject base;
+ struct QObjectBase_ base;
};
extern QNull qnull_;
diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h
index 3e47475b2c..45bf02a036 100644
--- a/include/qapi/qmp/qnum.h
+++ b/include/qapi/qmp/qnum.h
@@ -45,7 +45,7 @@ typedef enum {
* convert under the hood.
*/
struct QNum {
- QObject base;
+ struct QObjectBase_ base;
QNumKind kind;
union {
int64_t i64;
diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h
index 5206ff9ee1..a713c0165b 100644
--- a/include/qapi/qmp/qobject.h
+++ b/include/qapi/qmp/qobject.h
@@ -34,13 +34,21 @@
#include "qapi/qapi-builtin-types.h"
-struct QObject {
+/* Not for use outside include/qapi/qmp/ */
+struct QObjectBase_ {
QType type;
size_t refcnt;
};
-/* Get the 'base' part of an object */
-#define QOBJECT(obj) (&(obj)->base)
+/* this struct must have no other members than base */
+struct QObject {
+ struct QObjectBase_ base;
+};
+
+#define QOBJECT(obj) ({ \
+ typeof(obj) _obj = (obj); \
+ _obj ? container_of(&(_obj)->base, QObject, base) : NULL; \
+})
/* High-level interface for qobject_incref() */
#define QINCREF(obj) \
@@ -68,8 +76,8 @@ QEMU_BUILD_BUG_MSG(QTYPE__MAX != 7,
static inline void qobject_init(QObject *obj, QType type)
{
assert(QTYPE_NONE < type && type < QTYPE__MAX);
- obj->refcnt = 1;
- obj->type = type;
+ obj->base.refcnt = 1;
+ obj->base.type = type;
}
/**
@@ -77,8 +85,9 @@ static inline void qobject_init(QObject *obj, QType type)
*/
static inline void qobject_incref(QObject *obj)
{
- if (obj)
- obj->refcnt++;
+ if (obj) {
+ obj->base.refcnt++;
+ }
}
/**
@@ -101,8 +110,8 @@ void qobject_destroy(QObject *obj);
*/
static inline void qobject_decref(QObject *obj)
{
- assert(!obj || obj->refcnt);
- if (obj && --obj->refcnt == 0) {
+ assert(!obj || obj->base.refcnt);
+ if (obj && --obj->base.refcnt == 0) {
qobject_destroy(obj);
}
}
@@ -112,8 +121,8 @@ static inline void qobject_decref(QObject *obj)
*/
static inline QType qobject_type(const QObject *obj)
{
- assert(QTYPE_NONE < obj->type && obj->type < QTYPE__MAX);
- return obj->type;
+ assert(QTYPE_NONE < obj->base.type && obj->base.type < QTYPE__MAX);
+ return obj->base.type;
}
/**
diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h
index 30ae260a7f..b3b3d444d2 100644
--- a/include/qapi/qmp/qstring.h
+++ b/include/qapi/qmp/qstring.h
@@ -16,7 +16,7 @@
#include "qapi/qmp/qobject.h"
struct QString {
- QObject base;
+ struct QObjectBase_ base;
char *string;
size_t length;
size_t capacity;