mirror of
https://github.com/xemu-project/xemu.git
synced 2025-03-01 17:07:28 +00:00

By moving the base fields to a QObjectBase_, QObject can be a type which also has a 'base' field. This allows writing a generic QOBJECT() macro that will work with any QObject type, including QObject itself. The container_of() macro ensures that the object to cast has a QObjectBase_ base field, giving some type safety guarantees. QObject must have no members but QObjectBase_ base, or else QOBJECT() breaks. QObjectBase_ is not a typedef and uses a trailing underscore to make it obvious it is not for normal use and to avoid potential abuse. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180419150145.24795-3-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
33 lines
547 B
C
33 lines
547 B
C
/*
|
|
* QNull
|
|
*
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
*
|
|
* Authors:
|
|
* Markus Armbruster <armbru@redhat.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU LGPL, version 2.1
|
|
* or later. See the COPYING.LIB file in the top-level directory.
|
|
*/
|
|
|
|
#ifndef QNULL_H
|
|
#define QNULL_H
|
|
|
|
#include "qapi/qmp/qobject.h"
|
|
|
|
struct QNull {
|
|
struct QObjectBase_ base;
|
|
};
|
|
|
|
extern QNull qnull_;
|
|
|
|
static inline QNull *qnull(void)
|
|
{
|
|
QINCREF(&qnull_);
|
|
return &qnull_;
|
|
}
|
|
|
|
bool qnull_is_equal(const QObject *x, const QObject *y);
|
|
|
|
#endif /* QNULL_H */
|