]> git.proxmox.com Git - mirror_qemu.git/blobdiff - include/qapi/qmp/qobject.h
qobject atomics osdep: Make a few macros more hygienic
[mirror_qemu.git] / include / qapi / qmp / qobject.h
index 9003b71fd32d416415748975cffc0cf126ea5e3b..89b97d88bcab08003dd253bea2342aae7ea6e914 100644 (file)
@@ -45,10 +45,16 @@ struct QObject {
     struct QObjectBase_ base;
 };
 
-#define QOBJECT(obj) ({                                         \
+/*
+ * Preprocessor sorcery ahead: use a different identifier for the
+ * local variable in each expansion, so we can nest macro calls
+ * without shadowing variables.
+ */
+#define QOBJECT_INTERNAL(obj, _obj) ({                          \
     typeof(obj) _obj = (obj);                                   \
-    _obj ? container_of(&(_obj)->base, QObject, base) : NULL;   \
+    _obj ? container_of(&_obj->base, QObject, base) : NULL;     \
 })
+#define QOBJECT(obj) QOBJECT_INTERNAL((obj), MAKE_IDENTFIER(_obj))
 
 /* Required for qobject_to() */
 #define QTYPE_CAST_TO_QNull     QTYPE_QNULL