yeahuh / rpms / qemu-kvm

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