[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 2/3] qobject: introduce QObjectCommon
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v2 2/3] qobject: introduce QObjectCommon |
Date: |
Wed, 28 Mar 2018 08:45:36 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 03/28/2018 08:07 AM, Marc-André Lureau wrote:
By moving the common fields to a QObjectCommon, QObject can be a type
which also has a 'base' QObjectCommon field. This allows to write 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 QObjectCommon base field, give me some type
safety guarantees. However, for it to work properly, all QObject types
must have 'base' at offset 0 (which is ensured by static checking from
previous patch)
Signed-off-by: Marc-André Lureau <address@hidden>
---
+++ b/include/qapi/qmp/qbool.h
@@ -17,7 +17,7 @@
#include "qapi/qmp/qobject.h"
struct QBool {
- QObject base;
+ struct QObjectCommon base;
Why no 'typedef struct QObjectCommon QObjectCommon' in scope to make
this simpler?
-/* Get the 'base' part of an object */
-#define QOBJECT(obj) (&(obj)->base)
+struct QObject {
+ struct QObjectCommon base;
+};
+
+#define QOBJECT(x) \
+ container_of(&(x)->base, QObject, base)
If I understand correctly, this still causes clang complaints when
called as QOBJECT(NULL). As long as we are touching this, should we
improve this macro to be friendly to NULL conversion?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[Qemu-devel] [PATCH v2 1/3] qobject: ensure base is at offset 0, Marc-André Lureau, 2018/03/28
[Qemu-devel] [PATCH v2 3/3] qobject: replace qobject_incref/QINCREF qobject_decref/QDECREF, Marc-André Lureau, 2018/03/28