[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 5/7] qapi: Introduce QAPI_LIST_APPEND
From: |
Eric Blake |
Subject: |
[PATCH v3 5/7] qapi: Introduce QAPI_LIST_APPEND |
Date: |
Wed, 23 Dec 2020 16:11:00 -0600 |
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>
---
include/qapi/util.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/include/qapi/util.h b/include/qapi/util.h
index 6178e98e97a5..8b4967990c0d 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, 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.29.2
- [PATCH v3 0/7] Common macros for QAPI list growth, Eric Blake, 2020/12/23
- [PATCH v3 2/7] rocker: Revamp fp_port_get_info, Eric Blake, 2020/12/23
- [PATCH v3 3/7] migration: Refactor migrate_cap_add, Eric Blake, 2020/12/23
- [PATCH v3 1/7] net: Clarify early exit condition, Eric Blake, 2020/12/23
- [PATCH v3 5/7] qapi: Introduce QAPI_LIST_APPEND,
Eric Blake <=
- [PATCH v3 6/7] qapi: Use QAPI_LIST_APPEND in trivial cases, Eric Blake, 2020/12/23
- [PATCH v3 7/7] qapi: More complex uses of QAPI_LIST_APPEND, Eric Blake, 2020/12/23
- [PATCH v3 4/7] qapi: Use QAPI_LIST_PREPEND() where possible, Eric Blake, 2020/12/23