aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2021-01-13 16:10:11 -0600
committerMarkus Armbruster <armbru@redhat.com>2021-01-28 08:08:45 +0100
commitdc13f40c6ba291e31d09053815c230ed88c8921f (patch)
tree3c72e00bf08374a22bf458315b41695716411dd8
parent240ee8bd31f7ff7407197588ae800ff554758b4d (diff)
downloadqemu-dc13f40c6ba291e31d09053815c230ed88c8921f.zip
qemu-dc13f40c6ba291e31d09053815c230ed88c8921f.tar.gz
qemu-dc13f40c6ba291e31d09053815c230ed88c8921f.tar.bz2
qapi: Introduce QAPI_LIST_APPEND
Similar to the existing QAPI_LIST_PREPEND, but designed for use where we want to preserve insertion order. Callers will be added in upcoming patches. Note the difference in signature: PREPEND takes List*, APPEND takes List**. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20210113221013.390592-4-eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
-rw-r--r--include/qapi/util.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/qapi/util.h b/include/qapi/util.h
index 6178e98..d7bfb30 100644
--- a/include/qapi/util.h
+++ b/include/qapi/util.h
@@ -37,4 +37,17 @@ int parse_qapi_name(const char *name, bool complete);
(list) = _tmp; \
} while (0)
+/*
+ * For any pointer to a GenericList @tail (usually the 'next' member of a
+ * list element), insert @element at the back and update the tail.
+ *
+ * Note that this macro evaluates @element exactly once, so it is safe
+ * to have side-effects with that argument.
+ */
+#define QAPI_LIST_APPEND(tail, element) do { \
+ *(tail) = g_malloc0(sizeof(**(tail))); \
+ (*(tail))->value = (element); \
+ (tail) = &(*(tail))->next; \
+} while (0)
+
#endif