shared/c-list: re-import from latest c-util/c-list
$ git subtree pull --prefix shared/c-list/ git@github.com:c-util/c-list.git 071841c28d96e9104761af815a7ea367390c3174 --squash
This commit is contained in:
@@ -366,6 +366,25 @@ static inline CList *c_list_last(CList *list) {
|
||||
_iter = (_safe), \
|
||||
_safe = c_list_entry((_safe)->_m.next, __typeof__(*_iter), _m)) \
|
||||
|
||||
/**
|
||||
* c_list_flush() - flush all entries from a list
|
||||
* @list: list to flush
|
||||
*
|
||||
* This unlinks all entries from the given list @list and reinitializes their
|
||||
* link-nodes via C_LIST_INIT().
|
||||
*
|
||||
* Note that the entries are not modified in any other way, nor is their memory
|
||||
* released. This function just unlinks them and resets all the list nodes. It
|
||||
* is particularly useful with temporary lists on the stack in combination with
|
||||
* the GCC-extension __attribute__((__cleanup__(arg))).
|
||||
*/
|
||||
static inline void c_list_flush(CList *list) {
|
||||
CList *iter, *safe;
|
||||
|
||||
c_list_for_each_safe_unlink(iter, safe, list)
|
||||
/* empty */ ;
|
||||
}
|
||||
|
||||
/**
|
||||
* c_list_length() - return number of linked entries, excluding the head
|
||||
* @list: list to operate on
|
||||
|
@@ -26,6 +26,7 @@ static void test_api(void) {
|
||||
assert(c_list_length(&list) == 0);
|
||||
assert(c_list_contains(&list, &list));
|
||||
assert(!c_list_contains(&list, &node.link));
|
||||
c_list_flush(&list);
|
||||
|
||||
/* basic link / unlink calls */
|
||||
|
||||
|
@@ -157,9 +157,28 @@ static void test_splice(void) {
|
||||
assert(c_list_last(&target) == &e2);
|
||||
}
|
||||
|
||||
static void test_flush(void) {
|
||||
CList e1 = C_LIST_INIT(e1), e2 = C_LIST_INIT(e2);
|
||||
|
||||
{
|
||||
__attribute__((__cleanup__(c_list_flush))) CList list1 = C_LIST_INIT(list1);
|
||||
__attribute__((__cleanup__(c_list_flush))) CList list2 = C_LIST_INIT(list2);
|
||||
|
||||
c_list_link_tail(&list2, &e1);
|
||||
c_list_link_tail(&list2, &e2);
|
||||
|
||||
assert(c_list_is_linked(&e1));
|
||||
assert(c_list_is_linked(&e2));
|
||||
}
|
||||
|
||||
assert(!c_list_is_linked(&e1));
|
||||
assert(!c_list_is_linked(&e2));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_iterators();
|
||||
test_swap();
|
||||
test_splice();
|
||||
test_flush();
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user