From: James Jones Date: Wed, 11 Aug 2021 16:41:38 +0000 (-0500) Subject: Add fr_lst_entry_inserted() to permit heap->LST migration (#4178) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91a5810dc9f207c2a0008de423315d6ec36b8ff4;p=thirdparty%2Ffreeradius-server.git Add fr_lst_entry_inserted() to permit heap->LST migration (#4178) --- diff --git a/src/lib/util/lst.h b/src/lib/util/lst.h index c472b67d9f2..8af034edccd 100644 --- a/src/lib/util/lst.h +++ b/src/lib/util/lst.h @@ -76,6 +76,17 @@ typedef int8_t (*fr_lst_cmp_t)(void const *a, void const *b); fr_lst_t *_fr_lst_alloc(TALLOC_CTX *ctx, fr_lst_cmp_t cmp, char const *type, size_t offset) CC_HINT(nonnull(2)); +/** Check if an entry is inserted into an LST. + * This checks a necessary condition for a fr_lst_index_t value to be + * that of an inserted entry. A more complete check would need the entry + * itself and a pointer to the fr_lst_t it may be inserted in. + * Provided here to let heap users move to LSTs. + */ +static inline bool fr_lst_entry_inserted(fr_lst_index_t lst_id) +{ + return (lst_id >= 0); +} + void *fr_lst_peek(fr_lst_t *lst) CC_HINT(nonnull); void *fr_lst_pop(fr_lst_t *lst) CC_HINT(nonnull); diff --git a/src/lib/util/lst_tests.c b/src/lib/util/lst_tests.c index 2aedd980181..d32bf1fd80a 100644 --- a/src/lib/util/lst_tests.c +++ b/src/lib/util/lst_tests.c @@ -63,12 +63,16 @@ static void lst_test_basic(void) values[j].data = temp; } - for (int i = 0; i < NVALUES; i++) fr_lst_insert(lst, &values[i]); + for (int i = 0; i < NVALUES; i++) { + TEST_CHECK(fr_lst_insert(lst, &values[i]) >= 0); + TEST_CHECK(fr_lst_entry_inserted(values[i].index)); + } for (int i = 0; i < NVALUES; i++) { heap_thing *value = fr_lst_pop(lst); TEST_CHECK(value != NULL); + TEST_CHECK(!fr_lst_entry_inserted(value->index)); TEST_CHECK(value->data == i); } talloc_free(lst);