]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add ISC_LIST_FOREACH(_SAFE) macros
authorOndřej Surý <ondrej@isc.org>
Mon, 24 Apr 2023 10:40:33 +0000 (12:40 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 25 Apr 2023 06:16:46 +0000 (08:16 +0200)
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

.clang-format
lib/isc/include/isc/list.h

index 6a8388bc918cebc932998164c978aff326dc2f7a..124d82a2696ccb83fc8f7d62425a2f42e97e8a67 100644 (file)
@@ -78,4 +78,4 @@ PenaltyBreakString: 80
 PenaltyExcessCharacter: 100
 Standard: Cpp11
 ContinuationIndentWidth: 8
-ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe' ]
+ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE' ]
index 2cf4437542dfa41031647966b3df99237427ee77..a168254d40b06aa2bd0a108b5d529f52df2a8050 100644 (file)
                INSIST(ISC_LIST_EMPTY(dest));   \
                ISC_LIST_MOVEUNSAFE(dest, src); \
        }
+
+/* clang-format off */
+#define ISC_LIST_FOREACH(list, elt, link)      \
+       for (elt = ISC_LIST_HEAD(list);         \
+            elt != NULL;                       \
+            elt = ISC_LIST_NEXT(elt, link))
+/* clang-format on */
+
+/* clang-format off */
+#define ISC_LIST_FOREACH_SAFE(list, elt, link, next)                                           \
+       for (elt = ISC_LIST_HEAD(list), next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL; \
+            elt != NULL;                                                                       \
+            elt = next, next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL)
+/* clang-format on */