list: add LIST_CLEAR() helper that empties the list

This commit is contained in:
David Tardon
2023-08-17 09:48:17 +02:00
parent c0083c9ce0
commit d327b7752f
2 changed files with 37 additions and 0 deletions
+12
View File
@@ -192,6 +192,18 @@
_p; \
})
#define LIST_CLEAR(name, head, free_func) \
_LIST_CLEAR(name, head, free_func, UNIQ_T(elem, UNIQ))
/* Clear the list, destroing each element with free_func */
#define _LIST_CLEAR(name, head, free_func, elem) \
({ \
typeof(head) elem; \
while ((elem = LIST_POP(name, head))) \
free_func(elem); \
head; \
})
/* Now include "macro.h", because we want our definition of assert() which the macros above use. We include
* it down here instead of up top, since macro.h pulls in log.h which in turn needs our own definitions. */
#include "macro.h"