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:52:45 +0200 [thread overview]
Message-ID: <CAMxuvay5MCUZTaY5KpW_jTRP=LMV2YhMkFquGgXxUuYH5r89fQ@mail.gmail.com> (raw)
In-Reply-To: <87efjfsgc3.fsf@dusky.pond.sub.org>
On Mon, Apr 16, 2018 at 10:31 AM, Markus Armbruster <armbru@redhat.com> wrote:
> Markus Armbruster <armbru@redhat.com> writes:
>
>> 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).
>>
>> 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.
>
> Uh, there's another reason: existing type casts from QObject * to
> subtypes. I just spotted one in tests/check-qdict.c:
>
> dst = (QDict *)qdict_crumple(src, &error_abort);
>
> There may well be more.
>
So we better have checks from patch 1, don't we?
next prev parent reply other threads:[~2018-04-16 16:52 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 [this message]
2018-04-16 16:51 ` Marc-André Lureau
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='CAMxuvay5MCUZTaY5KpW_jTRP=LMV2YhMkFquGgXxUuYH5r89fQ@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).