]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add fr_lst_entry_inserted() to permit heap->LST migration (#4178)
authorJames Jones <jejones3141@gmail.com>
Wed, 11 Aug 2021 16:41:38 +0000 (11:41 -0500)
committerGitHub <noreply@github.com>
Wed, 11 Aug 2021 16:41:38 +0000 (10:41 -0600)
src/lib/util/lst.h
src/lib/util/lst_tests.c

index c472b67d9f2aa65f9a412c23f83de9c8456e3109..8af034edccd41b5078f0aeb625d0e142f5e57917 100644 (file)
@@ -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);
index 2aedd9801816db640aa225b17e1238d8c176c544..d32bf1fd80af9b94de7cbd78c7aefe01e4a36d2a 100644 (file)
@@ -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);