diff options
-rw-r--r-- | doc/internal/man3/DEFINE_LIST_OF.pod | 14 | ||||
-rw-r--r-- | include/internal/list.h | 11 | ||||
-rw-r--r-- | test/list_test.c | 6 |
3 files changed, 29 insertions, 2 deletions
diff --git a/doc/internal/man3/DEFINE_LIST_OF.pod b/doc/internal/man3/DEFINE_LIST_OF.pod index a0090c7685..311c200b7a 100644 --- a/doc/internal/man3/DEFINE_LIST_OF.pod +++ b/doc/internal/man3/DEFINE_LIST_OF.pod @@ -3,7 +3,8 @@ =head1 NAME DEFINE_LIST_OF, OSSL_LIST_MEMBER, OSSL_LIST, -ossl_list_TYPE_init, ossl_list_TYPE_num, +ossl_list_TYPE_init, ossl_list_TYPE_init_elem, +ossl_list_TYPE_is_empty, ossl_list_TYPE_num, ossl_list_TYPE_head, ossl_list_TYPE_tail, ossl_list_TYPE_next, ossl_list_TYPE_prev, ossl_list_TYPE_remove, ossl_list_TYPE_insert_head, ossl_list_TYPE_insert_tail, @@ -21,7 +22,9 @@ ossl_list_TYPE_insert_before, ossl_list_TYPE_after DEFINE_LIST_OF(NAME, TYPE); void ossl_list_TYPE_init(OSSL_LIST(name) *list); + void ossl_list_TYPE_init_elem(type *elem); + int ossl_list_TYPE_is_empty(const OSSL_LIST(name) *list); size_t ossl_list_TYPE_num(const OSSL_LIST(name) *list); type *ossl_list_TYPE_head(const OSSL_LIST(name) *list); type *ossl_list_TYPE_tail(const OSSL_LIST(name) *list); @@ -56,6 +59,12 @@ B<OSSL_LIST_MEMBER>(B<I<NAME>>, B<I<TYPE>>) field. B<ossl_list_I<NAME>_init>() initialises the memory pointed to by I<list> to zero which creates an empty list. +B<ossl_list_I<NAME>_init_elem>() initialises the list related memory pointed +to by I<elem> to zero which allows it to be used in lists. + +B<ossl_list_I<NAME>_is_empty>() returns nonzero if I<list> has no elements and +zero otherwise. + B<ossl_list_I<NAME>_num>() returns the number of elements in I<list>. B<ossl_list_I<NAME>_head>() returns the first element in the I<list> @@ -83,6 +92,9 @@ I<existing> element. =head1 RETURN VALUES +B<ossl_list_I<NAME>_is_empty>() returns nonzero if the list is empty and zero +otherwise. + B<ossl_list_I<NAME>_num>() returns the number of elements in the list. diff --git a/include/internal/list.h b/include/internal/list.h index aaf4e9b9da..8cb71e1fa4 100644 --- a/include/internal/list.h +++ b/include/internal/list.h @@ -33,6 +33,17 @@ { \ memset(list, 0, sizeof(*list)); \ } \ + static ossl_unused ossl_inline void \ + ossl_list_##name##_init_elem(type *elem) \ + { \ + memset(&elem->ossl_list_ ## name, 0, \ + sizeof(elem->ossl_list_ ## name)); \ + } \ + static ossl_unused ossl_inline int \ + ossl_list_##name##_is_empty(const OSSL_LIST(name) *list) \ + { \ + return list->num_elems == 0; \ + } \ static ossl_unused ossl_inline size_t \ ossl_list_##name##_num(const OSSL_LIST(name) *list) \ { \ diff --git a/test/list_test.c b/test/list_test.c index 908634d1f4..000f7beec3 100644 --- a/test/list_test.c +++ b/test/list_test.c @@ -39,6 +39,9 @@ static int test_fizzbuzz(void) ossl_list_fizz_init(&a); ossl_list_buzz_init(&b); + if (!TEST_true(ossl_list_fizz_is_empty(&a))) + return 0; + for (i = 1; i < nelem; i++) { elem[i].n = i; if (i % 3 == 0) { @@ -51,7 +54,8 @@ static int test_fizzbuzz(void) } } - if (!TEST_size_t_eq(ossl_list_fizz_num(&a), na) + if (!TEST_false(ossl_list_fizz_is_empty(&a)) + || !TEST_size_t_eq(ossl_list_fizz_num(&a), na) || !TEST_size_t_eq(ossl_list_buzz_num(&b), nb) || !TEST_ptr(ossl_list_fizz_head(&a)) || !TEST_ptr(ossl_list_fizz_tail(&a)) |