summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2019-05-25 10:50:41 -0700
committerRob Clark <[email protected]>2019-05-30 22:11:26 +0000
commit372e83b95f9277fe1d09b1c65c70a38918843b6f (patch)
tree7a2fdac4e55a2d6d3dda81e73f2efff96387aa97 /src/util
parent03ce12c5ed7d1225d5aad8c10fccab2503920ec0 (diff)
list: add some iterator debug
Debugging use of unsafe iterators when you should have used the _safe version sucks. Add some DEBUG build support to catch and assert if someone does that. I didn't update the UPPERCASE verions of the iterators. They should probably be deprecated/removed. Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Erik Faye-Lund <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/list.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/util/list.h b/src/util/list.h
index 09d1b4cae64..96e2f24695c 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -43,6 +43,11 @@
#include <assert.h>
#include "c99_compat.h"
+#ifdef DEBUG
+# define list_assert(cond, msg) assert(cond && msg)
+#else
+# define list_assert(cond, msg) (void)(0 && (cond))
+#endif
struct list_head
{
@@ -212,21 +217,27 @@ static inline void list_validate(const struct list_head *list)
pos = container_of(pos->member.prev, pos, member))
#define list_for_each_entry(type, pos, head, member) \
- for (type *pos = LIST_ENTRY(type, (head)->next, member); \
+ for (type *pos = LIST_ENTRY(type, (head)->next, member), \
+ *__next = LIST_ENTRY(type, pos->member.next, member); \
&pos->member != (head); \
- pos = LIST_ENTRY(type, pos->member.next, member))
+ pos = LIST_ENTRY(type, pos->member.next, member), \
+ list_assert(pos == __next, "use _safe iterator"), \
+ __next = LIST_ENTRY(type, __next->member.next, member))
#define list_for_each_entry_safe(type, pos, head, member) \
for (type *pos = LIST_ENTRY(type, (head)->next, member), \
*__next = LIST_ENTRY(type, pos->member.next, member); \
&pos->member != (head); \
pos = __next, \
- __next = LIST_ENTRY(type, __next->member.next, member))
+ __next = LIST_ENTRY(type, __next->member.next, member))
#define list_for_each_entry_rev(type, pos, head, member) \
- for (type *pos = LIST_ENTRY(type, (head)->prev, member); \
+ for (type *pos = LIST_ENTRY(type, (head)->prev, member), \
+ *__prev = LIST_ENTRY(type, pos->member.prev, member); \
&pos->member != (head); \
- pos = LIST_ENTRY(type, pos->member.prev, member))
+ pos = LIST_ENTRY(type, pos->member.prev, member), \
+ list_assert(pos == __prev, "use _safe iterator"), \
+ __prev = LIST_ENTRY(type, __prev->member.prev, member))
#define list_for_each_entry_safe_rev(type, pos, head, member) \
for (type *pos = LIST_ENTRY(type, (head)->prev, member), \