[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: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0 |
Date: |
Wed, 21 Mar 2018 18:43:42 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 21/03/2018 18:23, Marc-André Lureau wrote:
>>
>> 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?
#define QOBJECT(x) \
container_of(&(x)->base, QObject, base)
where the double dereference-and-container_of provides some type safety
(container_of fails if &(x)->base is not a QObjectCommon*).
Paolo
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, (continued)
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, Marc-André Lureau, 2018/03/21
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, Paolo Bonzini, 2018/03/21
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, Marc-André Lureau, 2018/03/21
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, Paolo Bonzini, 2018/03/21
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, Marc-André Lureau, 2018/03/21
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, Eric Blake, 2018/03/21
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, Marc-André Lureau, 2018/03/21
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0, Eric Blake, 2018/03/21
- Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0,
Paolo Bonzini <=
[Qemu-devel] [PATCH 3/3] qobject: replace qobject_incref/QINCREF qobject_decref/QDECREF, Marc-André Lureau, 2018/03/21
Re: [Qemu-devel] [PATCH 0/3] RFC: simplify qobject refcount, Eric Blake, 2018/03/21