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