[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 3/5] qapi: Introduce QAPI_LIST_APPEND
From: |
Markus Armbruster |
Subject: |
[PULL 3/5] qapi: Introduce QAPI_LIST_APPEND |
Date: |
Thu, 28 Jan 2021 08:45:04 +0100 |
From: Eric Blake <eblake@redhat.com>
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>
---
include/qapi/util.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/include/qapi/util.h b/include/qapi/util.h
index 6178e98e97..d7bfb30e25 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
--
2.26.2
- [PULL 0/5] QAPI patches patches for 2021-01-28, Markus Armbruster, 2021/01/28
- [PULL 3/5] qapi: Introduce QAPI_LIST_APPEND,
Markus Armbruster <=
- [PULL 1/5] net: Clarify early exit condition, Markus Armbruster, 2021/01/28
- [PULL 2/5] qapi: A couple more QAPI_LIST_PREPEND() stragglers, Markus Armbruster, 2021/01/28
- [PULL 5/5] qapi: More complex uses of QAPI_LIST_APPEND, Markus Armbruster, 2021/01/28
- [PULL 4/5] qapi: Use QAPI_LIST_APPEND in trivial cases, Markus Armbruster, 2021/01/28
- Re: [PULL 0/5] QAPI patches patches for 2021-01-28, Peter Maydell, 2021/01/29