Mesa (glsl2): exec_list: Fix foreach_list_safe.

Ian Romanick idr at kemper.freedesktop.org
Mon Jul 19 21:54:44 UTC 2010


Module: Mesa
Branch: glsl2
Commit: 61a44ccaef63a8ad36ebd934e6944ede5587e4d5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=61a44ccaef63a8ad36ebd934e6944ede5587e4d5

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Mon Jul 19 14:49:34 2010 -0700

exec_list: Fix foreach_list_safe.

It now works correctly when nodes are removed, as it was originally
intended to do; it no longer processes nodes added to the list before
the current node, nor those added immediately after the current node.

This matches the behavior of Linux's list_for_each_safe.

---

 src/glsl/ir_hv_accept.cpp |    5 +++--
 src/glsl/list.h           |   16 +++++-----------
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp
index 46bc5b1..8989605 100644
--- a/src/glsl/ir_hv_accept.cpp
+++ b/src/glsl/ir_hv_accept.cpp
@@ -32,9 +32,10 @@
 /**
  * Process a list of nodes using a hierarchical vistor
  *
+ * \warning
  * This function will operate correctly if a node being processed is removed
- * from the list.  If nodes are inserted before the current node, they will be
- * processed next.
+ * from the list.  However, if nodes are added to the list after the node being
+ * processed, some of the added nodes may not be processed.
  */
 ir_visitor_status
 visit_list_elements(ir_hierarchical_visitor *v, exec_list *l)
diff --git a/src/glsl/list.h b/src/glsl/list.h
index 29997c7..7348e32 100644
--- a/src/glsl/list.h
+++ b/src/glsl/list.h
@@ -433,18 +433,12 @@ struct exec_list {
 };
 
 /**
- * This version is safe even if the current node is removed.  If you insert
- * new nodes before the current node, they will be processed next.
- *
- * \note
- * The extra test for \c __node being \c NULL is required because after the
- * iteration \c __prev coupld be the last node in the list.  The loop increment
- * then causes \c __prev to point to the sentinal and \c __node to be \c NULL.
+ * This version is safe even if the current node is removed.
  */ 
-#define foreach_list_safe(__node, __list)		\
-   for (exec_node * __prev = (exec_node *) (__list), * __node = (__list)->head \
-        ; __node != NULL && (__node)->next != NULL	\
-	; __prev = (__prev)->next, __node = (__prev)->next)
+#define foreach_list_safe(__node, __list)			     \
+   for (exec_node * __node = (__list)->head, * __next = __node->next \
+	; __next != NULL					     \
+	; __node = __next, __next = __next->next)
 
 #define foreach_list(__node, __list)			\
    for (exec_node * __node = (__list)->head		\




More information about the mesa-commit mailing list