yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ae23c9
From d177d54c7ca08f3fff5824d69d4e66ca05a4eaf8 Mon Sep 17 00:00:00 2001
ae23c9
From: Markus Armbruster <armbru@redhat.com>
ae23c9
Date: Mon, 18 Jun 2018 08:43:09 +0200
ae23c9
Subject: [PATCH 011/268] qobject: Ensure base is at offset 0
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: Markus Armbruster <armbru@redhat.com>
ae23c9
Message-id: <20180618084330.30009-3-armbru@redhat.com>
ae23c9
Patchwork-id: 80724
ae23c9
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 02/23] qobject: Ensure base is at offset 0
ae23c9
Bugzilla: 1557995
ae23c9
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ae23c9
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
ae23c9
From: Marc-André Lureau <marcandre.lureau@redhat.com>
ae23c9
ae23c9
All QObject types have the base QObject as their first field. This
ae23c9
allows the simplification of qobject_to().
ae23c9
ae23c9
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
Message-Id: <20180419150145.24795-2-marcandre.lureau@redhat.com>
ae23c9
Reviewed-by: Markus Armbruster <armbru@redhat.com>
ae23c9
[Commit message paragraph on type casts dropped, to avoid giving the
ae23c9
impression type casting would be okay]
ae23c9
Signed-off-by: Markus Armbruster <armbru@redhat.com>
ae23c9
(cherry picked from commit 7ee9edfdb117da47c86c9764d90f0be11a648666)
ae23c9
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 include/qapi/qmp/qobject.h | 5 ++---
ae23c9
 qobject/qobject.c          | 9 +++++++++
ae23c9
 2 files changed, 11 insertions(+), 3 deletions(-)
ae23c9
ae23c9
diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h
ae23c9
index e022707..5206ff9 100644
ae23c9
--- a/include/qapi/qmp/qobject.h
ae23c9
+++ b/include/qapi/qmp/qobject.h
ae23c9
@@ -61,9 +61,8 @@ struct QObject {
ae23c9
 QEMU_BUILD_BUG_MSG(QTYPE__MAX != 7,
ae23c9
                    "The QTYPE_CAST_TO_* list needs to be extended");
ae23c9
 
ae23c9
-#define qobject_to(type, obj) ({ \
ae23c9
-    QObject *_tmp = qobject_check_type(obj, glue(QTYPE_CAST_TO_, type)); \
ae23c9
-    _tmp ? container_of(_tmp, type, base) : (type *)NULL; })
ae23c9
+#define qobject_to(type, obj)                                       \
ae23c9
+    ((type *)qobject_check_type(obj, glue(QTYPE_CAST_TO_, type)))
ae23c9
 
ae23c9
 /* Initialize an object to default values */
ae23c9
 static inline void qobject_init(QObject *obj, QType type)
ae23c9
diff --git a/qobject/qobject.c b/qobject/qobject.c
ae23c9
index 23600aa..87649c5 100644
ae23c9
--- a/qobject/qobject.c
ae23c9
+++ b/qobject/qobject.c
ae23c9
@@ -16,6 +16,15 @@
ae23c9
 #include "qapi/qmp/qlist.h"
ae23c9
 #include "qapi/qmp/qstring.h"
ae23c9
 
ae23c9
+QEMU_BUILD_BUG_MSG(
ae23c9
+    offsetof(QNull, base) != 0 ||
ae23c9
+    offsetof(QNum, base) != 0 ||
ae23c9
+    offsetof(QString, base) != 0 ||
ae23c9
+    offsetof(QDict, base) != 0 ||
ae23c9
+    offsetof(QList, base) != 0 ||
ae23c9
+    offsetof(QBool, base) != 0,
ae23c9
+    "base qobject must be at offset 0");
ae23c9
+
ae23c9
 static void (*qdestroy[QTYPE__MAX])(QObject *) = {
ae23c9
     [QTYPE_NONE] = NULL,               /* No such object exists */
ae23c9
     [QTYPE_QNULL] = NULL,              /* qnull_ is indestructible */
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9