Skip to content

Commit ae997d9

Browse files
committed
Add ISC_LIST_FOREACH(_SAFE) macros
There's a recurring pattern walking the ISC_LISTs that just repeats over and over. Add two macros: * ISC_LIST_FOREACH(list, elt, link) - walk the static list * ISC_LIST_FOREACH_SAFE(list, elt, link, next) - walk the list in a manner that's safe against list member deletions
1 parent f0c3881 commit ae997d9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ PenaltyBreakString: 80
7878
PenaltyExcessCharacter: 100
7979
Standard: Cpp11
8080
ContinuationIndentWidth: 8
81-
ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe' ]
81+
ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE' ]

lib/isc/include/isc/list.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,17 @@
227227
INSIST(ISC_LIST_EMPTY(dest)); \
228228
ISC_LIST_MOVEUNSAFE(dest, src); \
229229
}
230+
231+
/* clang-format off */
232+
#define ISC_LIST_FOREACH(list, elt, link) \
233+
for (elt = ISC_LIST_HEAD(list); \
234+
elt != NULL; \
235+
elt = ISC_LIST_NEXT(elt, link))
236+
/* clang-format on */
237+
238+
/* clang-format off */
239+
#define ISC_LIST_FOREACH_SAFE(list, elt, link, next) \
240+
for (elt = ISC_LIST_HEAD(list), next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL; \
241+
elt != NULL; \
242+
elt = next, next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL)
243+
/* clang-format on */

0 commit comments

Comments
 (0)