Apart from being safer from the point of view of potential undefined
behavior, the multi-variable version of the safe iterators have the
benefit of not requiring the declaration of an external variable to hold
the next position.

This patch removes the NEXT variable from all HINDEX_*_SAFE macros and
all of its callers.

Signed-off-by: Adrian Moreno <[email protected]>
---
 lib/conntrack.c     |  4 ++--
 lib/hindex.h        | 18 ++++++++----------
 tests/test-hindex.c |  4 ++--
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/lib/conntrack.c b/lib/conntrack.c
index 9c96b69e4..2f0777102 100644
--- a/lib/conntrack.c
+++ b/lib/conntrack.c
@@ -2857,8 +2857,8 @@ expectation_clean(struct conntrack *ct, const struct 
conn_key *parent_key)
 {
     ovs_rwlock_wrlock(&ct->resources_lock);
 
-    struct alg_exp_node *node, *next;
-    HINDEX_FOR_EACH_WITH_HASH_SAFE (node, next, node_ref,
+    struct alg_exp_node *node;
+    HINDEX_FOR_EACH_WITH_HASH_SAFE (node, node_ref,
                                     conn_key_hash(parent_key, ct->hash_basis),
                                     &ct->alg_expectation_refs) {
         if (!conn_key_cmp(&node->parent_key, parent_key)) {
diff --git a/lib/hindex.h b/lib/hindex.h
index 7b122744a..2c6e11120 100644
--- a/lib/hindex.h
+++ b/lib/hindex.h
@@ -134,13 +134,12 @@ void hindex_remove(struct hindex *, struct hindex_node *);
 
 /* Safe when NODE may be freed (not needed when NODE may be removed from the
  * hash map but its members remain accessible and intact). */
-#define HINDEX_FOR_EACH_WITH_HASH_SAFE(NODE, NEXT, MEMBER, HASH, HINDEX)    \
-    for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER,                               \
-                                hindex_node_with_hash(HINDEX, HASH),        \
-                                (void) NEXT);                               \
-         CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL,                    \
-                                 ITER_NEXT_VAR(NODE) = ITER_VAR(NODE)->s,   \
-                                 NODE, MEMBER);                             \
+#define HINDEX_FOR_EACH_WITH_HASH_SAFE(NODE, MEMBER, HASH, HINDEX)            \
+    for (INIT_MULTIVAR_SAFE(NODE, MEMBER,                                     \
+                            hindex_node_with_hash(HINDEX, HASH));             \
+         CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL,                      \
+                                 ITER_NEXT_VAR(NODE) = ITER_VAR(NODE)->s,     \
+                                 NODE, MEMBER);                               \
          UPDATE_MULTIVAR_SAFE(NODE))
 
 /* Returns the head node in 'hindex' with the given 'hash', or a null pointer
@@ -167,9 +166,8 @@ hindex_node_with_hash(const struct hindex *hindex, size_t 
hash)
 
 /* Safe when NODE may be freed (not needed when NODE may be removed from the
  * hash index but its members remain accessible and intact). */
-#define HINDEX_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HINDEX)                      \
-    for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, hindex_first(HINDEX), \
-                                (void) NEXT);                                 \
+#define HINDEX_FOR_EACH_SAFE(NODE, MEMBER, HINDEX)                            \
+    for (INIT_MULTIVAR_SAFE(NODE, MEMBER, hindex_first(HINDEX));              \
          CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL,                      \
               ITER_NEXT_VAR(NODE) = hindex_next(HINDEX, ITER_VAR(NODE)),      \
               NODE, MEMBER);                                                  \
diff --git a/tests/test-hindex.c b/tests/test-hindex.c
index af06be5fc..93b5308b2 100644
--- a/tests/test-hindex.c
+++ b/tests/test-hindex.c
@@ -256,7 +256,7 @@ test_hindex_for_each_safe(hash_func *hash)
             struct element elements[MAX_ELEMS];
             int values[MAX_ELEMS];
             struct hindex hindex;
-            struct element *e, *next;
+            struct element *e;
             size_t n_remaining;
             int i;
 
@@ -264,7 +264,7 @@ test_hindex_for_each_safe(hash_func *hash)
 
             i = 0;
             n_remaining = n;
-            HINDEX_FOR_EACH_SAFE (e, next, node, &hindex) {
+            HINDEX_FOR_EACH_SAFE (e, node, &hindex) {
                 assert(i < n);
                 if (pattern & (1ul << e->value)) {
                     size_t j;
-- 
2.34.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to