]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add ISC_LIST_FOREACH_REV(_SAFE) macros
authorOndřej Surý <ondrej@isc.org>
Thu, 19 Oct 2023 08:21:20 +0000 (10:21 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 25 Oct 2023 10:36:13 +0000 (12:36 +0200)
Add complementary macros to ISC_LIST_FOREACH(_SAFE) that walk the lists
in reverse.

  * ISC_LIST_FOREACH_REV(list, elt, link) - walk the static list from
    tail to head
  * ISC_LIST_FOREACH_REV_SAFE(list, elt, link, next) - walk the list
    from tail to head in a manner that's safe against list member
    deletions

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

index 124d82a2696ccb83fc8f7d62425a2f42e97e8a67..54a39fdb4d4fbcd0dc7fabb5374f2f00efa1f73f 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', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE' ]
+ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE', 'ISC_LIST_FOREACH_REV', 'ISC_LIST_FOREACH_REV_SAFE' ]
index a168254d40b06aa2bd0a108b5d529f52df2a8050..67ed208c2c0c34e94f644679a136731b57e79504 100644 (file)
             elt != NULL;                                                                       \
             elt = next, next = (elt != NULL) ? ISC_LIST_NEXT(elt, link) : NULL)
 /* clang-format on */
+
+/* clang-format off */
+#define ISC_LIST_FOREACH_REV(list, elt, link)  \
+       for (elt = ISC_LIST_TAIL(list);         \
+            elt != NULL;                       \
+            elt = ISC_LIST_PREV(elt, link))
+/* clang-format on */
+
+/* clang-format off */
+#define ISC_LIST_FOREACH_REV_SAFE(list, elt, link, prev)                                               \
+       for (elt = ISC_LIST_TAIL(list), prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL; \
+            elt != NULL;                                                                       \
+            elt = prev, prev = (elt != NULL) ? ISC_LIST_PREV(elt, link) : NULL)
+/* clang-format on */