[ovs-dev] [PATCH v7 2/4] util.h: add token concatenation macro with argument expansion

Paolo Valerio pvalerio at redhat.com
Mon Jun 21 10:06:25 UTC 2021


this macro is handy when it comes paste two tokens when one or both
are macros.

Rename CURSOR_JOIN() to OVS_JOIN() and move it to util.h so that it can
be reused.

Signed-off-by: Paolo Valerio <pvalerio at redhat.com>
Acked-by: Gaetan Rivet <grive at u256.net>
Acked-by: Aaron Conole <aconole at redhat.com>
---
 lib/cmap.h |    5 +----
 lib/util.h |    7 +++++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/cmap.h b/lib/cmap.h
index d9db3c915..c502d2311 100644
--- a/lib/cmap.h
+++ b/lib/cmap.h
@@ -245,9 +245,6 @@ void cmap_cursor_advance(struct cmap_cursor *);
 
 /* Generate a unique name for the cursor with the __COUNTER__ macro to
  * allow nesting of CMAP_FOR_EACH loops. */
-#define CURSOR_JOIN2(x,y) x##y
-#define CURSOR_JOIN(x, y) CURSOR_JOIN2(x,y)
-
 #define CMAP_FOR_EACH__(NODE, MEMBER, CMAP, CURSOR_NAME)           \
     for (struct cmap_cursor CURSOR_NAME = cmap_cursor_start(CMAP); \
          CMAP_CURSOR_FOR_EACH__(NODE, &CURSOR_NAME, MEMBER);       \
@@ -255,7 +252,7 @@ void cmap_cursor_advance(struct cmap_cursor *);
 
 #define CMAP_FOR_EACH(NODE, MEMBER, CMAP) \
           CMAP_FOR_EACH__(NODE, MEMBER, CMAP, \
-                CURSOR_JOIN(cursor_, __COUNTER__))
+                OVS_JOIN(cursor_, __COUNTER__))
 
 static inline struct cmap_node *cmap_first(const struct cmap *);
 
diff --git a/lib/util.h b/lib/util.h
index 1fe8ef32b..aea19d45f 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -105,6 +105,13 @@ ovs_prefetch_range(const void *start, size_t size)
 
 #define OVS_NOT_REACHED() abort()
 
+/* Joins two token expanding the arguments if they are macros.
+ *
+ * For token concatenation the circumlocution is needed for the
+ * expansion. */
+#define OVS_JOIN2(X, Y) X##Y
+#define OVS_JOIN(X, Y) OVS_JOIN2(X, Y)
+
 /* Use "%"PRIuSIZE to format size_t with printf(). */
 #ifdef _WIN32
 #define PRIdSIZE "Id"



More information about the dev mailing list