aboutsummaryrefslogtreecommitdiff
path: root/qobject/qobject.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-04-19 17:01:42 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-05-04 08:27:53 +0200
commit3d3eacaeccaab718ea0e2ddaa578bfae9e311c59 (patch)
treee0f8f345f94f9de6b203da0e4a8ff06b23e4c5ae /qobject/qobject.c
parent7ee9edfdb117da47c86c9764d90f0be11a648666 (diff)
qobject: use a QObjectBase_ struct
By moving the base fields to a QObjectBase_, QObject can be a type which also has a 'base' field. This allows writing a generic QOBJECT() macro that will work with any QObject type, including QObject itself. The container_of() macro ensures that the object to cast has a QObjectBase_ base field, giving some type safety guarantees. QObject must have no members but QObjectBase_ base, or else QOBJECT() breaks. QObjectBase_ is not a typedef and uses a trailing underscore to make it obvious it is not for normal use and to avoid potential abuse. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180419150145.24795-3-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'qobject/qobject.c')
-rw-r--r--qobject/qobject.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/qobject/qobject.c b/qobject/qobject.c
index 87649c5be5..cf4b7e229e 100644
--- a/qobject/qobject.c
+++ b/qobject/qobject.c
@@ -37,9 +37,9 @@ static void (*qdestroy[QTYPE__MAX])(QObject *) = {
void qobject_destroy(QObject *obj)
{
- assert(!obj->refcnt);
- assert(QTYPE_QNULL < obj->type && obj->type < QTYPE__MAX);
- qdestroy[obj->type](obj);
+ assert(!obj->base.refcnt);
+ assert(QTYPE_QNULL < obj->base.type && obj->base.type < QTYPE__MAX);
+ qdestroy[obj->base.type](obj);
}
@@ -62,11 +62,11 @@ bool qobject_is_equal(const QObject *x, const QObject *y)
return true;
}
- if (!x || !y || x->type != y->type) {
+ if (!x || !y || x->base.type != y->base.type) {
return false;
}
- assert(QTYPE_NONE < x->type && x->type < QTYPE__MAX);
+ assert(QTYPE_NONE < x->base.type && x->base.type < QTYPE__MAX);
- return qis_equal[x->type](x, y);
+ return qis_equal[x->base.type](x, y);
}