All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	"P. Berrange, Daniel" <berrange@redhat.com>,
	"Armbruster, Markus" <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0
Date: Wed, 21 Mar 2018 09:19:18 -0500	[thread overview]
Message-ID: <4e876850-3057-e9d5-695b-69f4cde9aa9a@redhat.com> (raw)
In-Reply-To: <CAMxuvay1j+E1YRggpqm9+ETE_FxD-ThGtPBenUtvt8oeYweS8g@mail.gmail.com>

On 03/21/2018 09:08 AM, Marc-André Lureau wrote:
> Hi
> 
> On Wed, Mar 21, 2018 at 3:01 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> On 21/03/2018 14:40, Marc-André Lureau wrote:
>>> +/* A typecast, checking for the type of arguments */
>>> +/* QObject is at offset 0, for all QObject-derived types */
>>> +#define QOBJECT(x) QEMU_GENERIC(x,              \
>>> +    (QNull *, (QObject *) x),                   \
>>> +    (const QNull *, (const QObject *) x),       \
>>> +    (QNum *, (QObject *) x),                    \
>>> +    (const QNum *, (const QObject *) x),        \
>>> +    (QString *, (QObject *) x),                 \
>>> +    (const QString *, (const QObject *) x),     \
>>> +    (QDict *, (QObject *) x),                   \
>>> +    (const QDict *, (const QObject *) x),       \
>>> +    (QList *, (QObject *) x),                   \
>>> +    (const QList *, (const QObject *) x),       \
>>> +    (QBool *, (QObject *) x),                   \
>>> +    (const QBool *, (const QObject *) x),       \
>>> +    (QObject *, x),                             \
>>> +    (const QObject *, x),                       \
>>> +    qobject_unknown_type(x))
>>
>> Why not just
>>
>>          QEMU_GENERIC(x,
>>                  (QObject *, x),
>>                  (const QObject *, x),
>>                  ({ \
>>                          QEMU_BUILD_BUG_ON(offsetof(typeof(*x), base));
>>                          &(x)->base;
>>                  }))
>>
>> That is just an extension of what was being done before, and it is
>> resilient against people putting a random "QObject base" in the middle
>> of a struct.
>>
> 
> Yeah, I tried a few of those approaches. Here the problem is that
> QObject doesn't have base field. So you get a compile time error with
> a QObject * as argument.

So the compiler requires &(x)->base to resolve even when it is not on 
the branch that gets selected?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

  reply	other threads:[~2018-03-21 14:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-21 13:40 [Qemu-devel] [PATCH 0/3] RFC: simplify qobject refcount Marc-André Lureau
2018-03-21 13:40 ` [Qemu-devel] [PATCH 1/3] compiler: extend QEMU_GENERIC to handle more arguments Marc-André Lureau
2018-03-21 13:40 ` [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0 Marc-André Lureau
2018-03-21 14:01   ` Paolo Bonzini
2018-03-21 14:08     ` Marc-André Lureau
2018-03-21 14:19       ` Eric Blake [this message]
2018-03-21 14:21         ` Marc-André Lureau
2018-03-21 14:49           ` Paolo Bonzini
2018-03-21 15:29             ` Eric Blake
2018-03-21 15:34               ` Paolo Bonzini
2018-03-21 15:55     ` Marc-André Lureau
2018-03-21 16:00       ` Paolo Bonzini
2018-03-21 16:11         ` Marc-André Lureau
2018-03-21 16:23           ` Paolo Bonzini
2018-03-21 16:59             ` Marc-André Lureau
2018-03-21 17:08               ` Eric Blake
2018-03-21 17:23                 ` Marc-André Lureau
2018-03-21 17:38                   ` Eric Blake
2018-03-21 17:43                   ` Paolo Bonzini
2018-03-21 14:01   ` Eric Blake
2018-03-21 14:02     ` Paolo Bonzini
2018-03-21 13:40 ` [Qemu-devel] [PATCH 3/3] qobject: replace qobject_incref/QINCREF qobject_decref/QDECREF Marc-André Lureau
2018-03-21 14:28   ` Eric Blake
2018-03-21 14:51     ` Marc-André Lureau
2018-03-21 15:36       ` Eric Blake
2018-03-21 14:09 ` [Qemu-devel] [PATCH 0/3] RFC: simplify qobject refcount Eric Blake
2018-03-21 14:19   ` 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=4e876850-3057-e9d5-695b-69f4cde9aa9a@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.