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: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0
Date: Wed, 21 Mar 2018 12:08:56 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

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).

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



reply via email to

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