diff mbox series

[ovs-dev,10/13] hindex: use multi-variable iterators

Message ID 20220124103445.2459400-11-amorenoz@redhat.com
State Superseded
Headers show
Series Fix undefined behavior in loop macros | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning

Commit Message

Adrian Moreno Jan. 24, 2022, 10:34 a.m. UTC
Re-write hindex's loops using multi-variable helpers.

For safe loops, keep the (now unused) NEXT variable to maintain
backwards compatibility.

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 lib/hindex.h | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

Comments

0-day Robot Jan. 24, 2022, 12:05 p.m. UTC | #1
Bleep bloop.  Greetings Adrian Moreno, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


Patch skipped due to previous failure.

Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
diff mbox series

Patch

diff --git a/lib/hindex.h b/lib/hindex.h
index 876c5a9e3..7b122744a 100644
--- a/lib/hindex.h
+++ b/lib/hindex.h
@@ -128,18 +128,20 @@  void hindex_remove(struct hindex *, struct hindex_node *);
  * Evaluates HASH only once.
  */
 #define HINDEX_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HINDEX)               \
-    for (INIT_CONTAINER(NODE, hindex_node_with_hash(HINDEX, HASH), MEMBER); \
-         NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER);                     \
-         ASSIGN_CONTAINER(NODE, (NODE)->MEMBER.s, MEMBER))
+    for (INIT_MULTIVAR(NODE, MEMBER, hindex_node_with_hash(HINDEX, HASH));  \
+         CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER);          \
+         UPDATE_MULTIVAR(ITER_VAR(NODE) = ITER_VAR(NODE)->s, 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_CONTAINER(NODE, hindex_node_with_hash(HINDEX, HASH), MEMBER); \
-         (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)                 \
-          ? INIT_CONTAINER(NEXT, (NODE)->MEMBER.s, MEMBER), 1           \
-          : 0);                                                         \
-         (NODE) = (NEXT))
+#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);                             \
+         UPDATE_MULTIVAR_SAFE(NODE))
 
 /* Returns the head node in 'hindex' with the given 'hash', or a null pointer
  * if no nodes have that hash value. */
@@ -157,19 +159,21 @@  hindex_node_with_hash(const struct hindex *hindex, size_t hash)
 /* Iteration. */
 
 /* Iterates through every node in HINDEX. */
-#define HINDEX_FOR_EACH(NODE, MEMBER, HINDEX)                           \
-    for (INIT_CONTAINER(NODE, hindex_first(HINDEX), MEMBER);            \
-         NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER);                 \
-         ASSIGN_CONTAINER(NODE, hindex_next(HINDEX, &(NODE)->MEMBER), MEMBER))
+#define HINDEX_FOR_EACH(NODE, MEMBER, HINDEX)                                 \
+    for (INIT_MULTIVAR(NODE, MEMBER, hindex_first(HINDEX));                   \
+         CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER);            \
+         UPDATE_MULTIVAR(ITER_VAR(NODE) = hindex_next(HINDEX, ITER_VAR(NODE)),\
+                         NODE))
 
 /* 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_CONTAINER(NODE, hindex_first(HINDEX), MEMBER);          \
-         (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)                 \
-          ? INIT_CONTAINER(NEXT, hindex_next(HINDEX, &(NODE)->MEMBER), MEMBER), 1 \
-          : 0);                                                         \
-         (NODE) = (NEXT))
+#define HINDEX_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HINDEX)                      \
+    for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, hindex_first(HINDEX), \
+                                (void) NEXT);                                 \
+         CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL,                      \
+              ITER_NEXT_VAR(NODE) = hindex_next(HINDEX, ITER_VAR(NODE)),      \
+              NODE, MEMBER);                                                  \
+         UPDATE_MULTIVAR_SAFE(NODE))
 
 struct hindex_node *hindex_first(const struct hindex *);
 struct hindex_node *hindex_next(const struct hindex *,