qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at off


From: Marc-André Lureau
Subject: Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0
Date: Wed, 21 Mar 2018 18:23:47 +0100

On Wed, Mar 21, 2018 at 6:08 PM, Eric Blake <address@hidden> wrote:
> On 03/21/2018 11:59 AM, Marc-André Lureau wrote:
>>>
>>> Hmm, perhaps by making it "struct {} base"?
>>>
>>> Or even:
>>>
>>> struct QObjectCommon {
>>>      QType type;
>>>      size_t refcnt;
>>> }
>>>
>>> struct QObject {
>>>      QObjectCommon base;
>>> }
>>>
>>> struct QString {
>>>      QObjectCommon base;
>>>      ...
>>> }
>>
>>
>> I fail to see what that solves. You are moving the problem to
>> QObjectCommon: we would have to replace all QObject * user to take
>> QObjectCommon *, and then we wouldn't solve the problem for
>> QObjectCommon.
>
>
> Here, QObjectCommon is never used outside of qobject.h; all existing code
> continues to uwe QObject *.  But the conversion from QString* or QObject *
> to QObjectCommon * is trivial (&obj->base), and the conversion from
> QObjectCommon * to the public QObject * is trivial (container_of style
> cast).  So the QOBJECT() macro becomes comparable to a C++
> reinterpret_cast<>() that converts any descendent of QObjectCommon into
> QObject, even if the original type was not QObject; and we never offer a
> public API to convert anything into or out of QObjectCommon (it only exists
> as a dummy type to make our other casts easier).

What is the QOJECT() macro you proposed with that?

thanks


-- 
Marc-André Lureau



reply via email to

[Prev in Thread] Current Thread [Next in Thread]