qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	"Bonzini, Paolo" <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 2/4] qobject: use a QObjectBase_ struct
Date: Mon, 16 Apr 2018 18:51:24 +0200	[thread overview]
Message-ID: <CAMxuvawfVz-Q-XemOXDzHPSB-pvOLw3-zERea1nYDRT5Nf0FJg@mail.gmail.com> (raw)
In-Reply-To: <87r2nfsh7w.fsf@dusky.pond.sub.org>

Hi

On Mon, Apr 16, 2018 at 10:12 AM, Markus Armbruster <armbru@redhat.com> wrote:
> 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. However, for it to work properly, all QObject types must
>> have 'base' at offset 0 (which is ensured by static checking from
>> the previous patch)
>
> I'm afraid this condition is neither sufficient nor necessary.
>
> QOBJECT() maps a pointer to some subtype to the base type QObject.  For
> this to work, the subtype must contain a QObject.
>
> Before the patch, this is trivially the case: the subtypes have a member
> QObject base, and QOBJECT() returns its address.
>
> Afterwards, the subtypes have a member QObjectBase_ base, and QOBJECT()
> returns the address of a notional QObject wrapped around this member.
> Works because QObject has no other members.
>
> The condition 'base is at offset 0' does not ensure this, and is
> therefore not sufficient.
>
> It's not necessary, either: putting base elsewhere would work just fine
> as long as we put *all* of QObject there.
>
> Please document the real condition "QObject must have no members but
> QObjectBase_ base, or else QOBJECT() breaks".  Feel free to check their
> sizes are the same (I wouldn't bother).

ok

>
> If requiring base to be at offset zero for all subtypes materially
> simplifies code, then go ahead and do that in a separate patch.  My gut
> feeling is it doesn't, but I could be wrong.

what is missing from patch 1?

>
>> QObjectBase_ is not typedef and use a trailing underscore to make it
>> obvious it is not for normal use and to avoid potential abuse.
>
> Trailing underscore I like, lack of typedef I don't mind (but I'm firmly
> in the "eschew typedef for structs" camp).  It does violate the common
> QEMU coding style, though.
>
> A comment /* Not for use outside include/qapi/qmp/ */ next to
> QObjectBase_ wouldn't hurt.
>

ok

  parent reply	other threads:[~2018-04-16 16:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-13 16:18 [Qemu-devel] [PATCH v4 0/4] RFC: simplify qobject refcount Marc-André Lureau
2018-04-13 16:18 ` [Qemu-devel] [PATCH v4 1/4] qobject: ensure base is at offset 0 Marc-André Lureau
2018-04-13 16:18 ` [Qemu-devel] [PATCH v4 2/4] qobject: use a QObjectBase_ struct Marc-André Lureau
2018-04-16  8:12   ` Markus Armbruster
2018-04-16  8:31     ` Markus Armbruster
2018-04-16 16:52       ` Marc-André Lureau
2018-04-16 16:51     ` Marc-André Lureau [this message]
2018-04-13 16:18 ` [Qemu-devel] [PATCH v4 3/4] qobject: replace qobject_incref/QINCREF qobject_decref/QDECREF Marc-André Lureau
2018-04-16  8:57   ` Markus Armbruster
2018-04-17 12:18     ` Marc-André Lureau
2018-04-13 16:18 ` [Qemu-devel] [PATCH v4 4/4] qobject: modify qobject_ref() to assert on NULL and return obj Marc-André Lureau
2018-04-16  8:26   ` Markus Armbruster
2018-04-16  9:38     ` Markus Armbruster
2018-04-17 13:29     ` Marc-André Lureau

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=CAMxuvawfVz-Q-XemOXDzHPSB-pvOLw3-zERea1nYDRT5Nf0FJg@mail.gmail.com \
    --to=marcandre.lureau@redhat.com \
    --cc=armbru@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).