From 1d5c4a63786b080948bc201e6f67634460d38aae Mon Sep 17 00:00:00 2001 From: jobo <38849089+jobo-zt@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:16:55 +0800 Subject: [PATCH 1/2] list: add the macro LIST_FOREACH_SAFE to support modification during linked list traversal --- include/re_list.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/re_list.h b/include/re_list.h index 8cf08f1a8..dcf3b6146 100644 --- a/include/re_list.h +++ b/include/re_list.h @@ -97,6 +97,9 @@ static inline bool list_isempty(const struct list *list) #define LIST_FOREACH(list, le) \ for ((le) = list_head((list)); (le); (le) = (le)->next) +#define LIST_FOREACH_SAFE(list, le, n) \ + for ((le) = list_head((list)), (n) = (le) ? (le)->next : NULL; (le); \ + (le) = (n), (n) = (le) ? (le)->next : NULL) /** * Move element to another linked list From 6d1c2dd6867e1db202454e55cf9997fad0eb2ae1 Mon Sep 17 00:00:00 2001 From: jobo <38849089+jobo-zt@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:50:20 +0800 Subject: [PATCH 2/2] Resolve IOS conflicts --- include/re_list.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/re_list.h b/include/re_list.h index dcf3b6146..d068a9f41 100644 --- a/include/re_list.h +++ b/include/re_list.h @@ -97,6 +97,7 @@ static inline bool list_isempty(const struct list *list) #define LIST_FOREACH(list, le) \ for ((le) = list_head((list)); (le); (le) = (le)->next) +#undef LIST_FOREACH_SAFE #define LIST_FOREACH_SAFE(list, le, n) \ for ((le) = list_head((list)), (n) = (le) ? (le)->next : NULL; (le); \ (le) = (n), (n) = (le) ? (le)->next : NULL)