Skip to content

Commit

Permalink
list.h: Add iterator macros
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #22674)
  • Loading branch information
hlandau committed Dec 21, 2023
1 parent 3f0be2c commit 70a7e54
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/internal/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@
# define OSSL_LIST_DBG(x) x;
# endif

# define LIST_FOREACH_FROM(p, name, init) \
for ((p) = (init); \
(p) != NULL; \
(p) = ossl_list_##name##_next(p))
# define LIST_FOREACH(p, name, l) \
LIST_FOREACH_FROM(p, name, ossl_list_##name##_head(l))

# define LIST_FOREACH_REV_FROM(p, name, init) \
for ((p) = (init); \
(p) != NULL; \
(p) = ossl_list_##name##_prev(p))
# define LIST_FOREACH_REV(p, name, l) \
LIST_FOREACH_FROM(p, name, ossl_list_##name##_tail(l))

# define LIST_FOREACH_DELSAFE_FROM(p, pn, name, init) \
for ((p) = (init); \
(p) != NULL && (((pn) = ossl_list_##name##_next(p)), 1); \
(p) = (pn))
#define LIST_FOREACH_DELSAFE(p, pn, name, l) \
LIST_FOREACH_DELSAFE_FROM(p, pn, name, ossl_list_##name##_head(l))

# define LIST_FOREACH_REV_DELSAFE_FROM(p, pn, name, init) \
for ((p) = (init); \
(p) != NULL && (((pn) = ossl_list_##name##_prev(p)), 1); \
(p) = (pn))
# define LIST_FOREACH_REV_DELSAFE(p, pn, name, l) \
LIST_FOREACH_REV_DELSAFE_FROM(p, pn, name, ossl_list_##name##_tail(l))

/* Define a list structure */
# define OSSL_LIST(name) OSSL_LIST_ ## name

Expand Down

0 comments on commit 70a7e54

Please sign in to comment.