From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v5 2/5] qobject: use a QObjectBase_ struct
Date: Thu, 19 Apr 2018 08:11:08 +0200 [thread overview]
Message-ID: <87d0yvybcz.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20180417133602.23832-3-marcandre.lureau@redhat.com> ("Marc-André Lureau"'s message of "Tue, 17 Apr 2018 15:35:59 +0200")
In addition to Eric's comments...
Marc-André Lureau <marcandre.lureau@redhat.com> writes:
> By moving the base fields to a QObjectBase_, QObject can be a type
> which also has a 'base' field. This allows to write 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 typedef and use 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>
[...]
> diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h
> index 5206ff9ee1..0a7f800d58 100644
> --- a/include/qapi/qmp/qobject.h
> +++ b/include/qapi/qmp/qobject.h
> @@ -34,13 +34,20 @@
>
> #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)
> +struct QObject {
> + struct QObjectBase_ base;
> +};
> +
> +#define QOBJECT(x) ({ \
> + typeof(x) __x = (x); \
> + __x ? container_of(&(__x)->base, QObject, base) : NULL; \
> +})
Identifiers that begin with double underscores are reserved for any
use. Drop one of the two, please.
>
> /* High-level interface for qobject_incref() */
> #define QINCREF(obj) \
> @@ -68,8 +75,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;
> }
>
> /**
[...]
next prev parent reply other threads:[~2018-04-19 6:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-17 13:35 [Qemu-devel] [PATCH v5 0/5] Simplify qobject refcount Marc-André Lureau
2018-04-17 13:35 ` [Qemu-devel] [PATCH v5 1/5] qobject: ensure base is at offset 0 Marc-André Lureau
2018-04-17 18:17 ` Eric Blake
2018-04-18 16:45 ` Markus Armbruster
2018-04-18 16:58 ` Marc-André Lureau
2018-04-18 17:04 ` Eric Blake
2018-04-19 6:07 ` Markus Armbruster
2018-04-17 13:35 ` [Qemu-devel] [PATCH v5 2/5] qobject: use a QObjectBase_ struct Marc-André Lureau
2018-04-17 18:33 ` Eric Blake
2018-04-19 6:11 ` Markus Armbruster [this message]
2018-04-17 13:36 ` [Qemu-devel] [PATCH v5 3/5] qobject: replace qobject_incref/QINCREF qobject_decref/QDECREF Marc-André Lureau
2018-04-17 18:46 ` Eric Blake
2018-04-19 6:16 ` Markus Armbruster
2018-04-19 14:27 ` Marc-André Lureau
2018-04-17 13:36 ` [Qemu-devel] [PATCH v5 4/5] qobject: modify qobject_ref() to return obj Marc-André Lureau
2018-04-17 18:50 ` Eric Blake
2018-04-19 6:25 ` Markus Armbruster
2018-04-17 13:36 ` [Qemu-devel] [PATCH v5 5/5] qobject: modify qobject_ref() to assert on NULL Marc-André Lureau
2018-04-17 18:51 ` Eric Blake
2018-04-19 6:18 ` Markus Armbruster
2018-04-19 13:37 ` Marc-André Lureau
2018-04-19 6:44 ` [Qemu-devel] [PATCH v5 0/5] Simplify qobject refcount Markus Armbruster
2018-04-19 10:09 ` Marc-André Lureau
2018-04-19 11:48 ` Marc-André Lureau
2018-04-19 13:13 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d0yvybcz.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).