From 6bd31037f468ca68c1fea5463d8ff786618467cd Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 29 Dec 2019 17:51:03 +0100 Subject: ptrlist: add pop_ptr_list() Some algorithms need a stack or a working list from which the last element can be removed. The ptrlist API has a function to do this but it's not typed and thus needs a wrapper for each type it's used for. Simplify this by adding a generic (but type-safe) macro for this while also giving it a nicer name: pop_ptr_list(). Signed-off-by: Luc Van Oostenryck --- ptrlist.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ptrlist.h b/ptrlist.h index 3b952097..0b061422 100644 --- a/ptrlist.h +++ b/ptrlist.h @@ -67,6 +67,12 @@ extern void **__add_ptr_list_tag(struct ptr_list **, void *, unsigned long); (__typeof__(&(ptr))) __add_ptr_list_tag(head, ptr, tag);\ }) +#define pop_ptr_list(l) ({ \ + PTRLIST_TYPE(*(l)) ptr; \ + ptr = delete_ptr_list_last((struct ptr_list**)(l)); \ + ptr; \ + }) + extern void __free_ptr_list(struct ptr_list **); #define free_ptr_list(list) do { \ VRFY_PTR_LIST(*(list)); \ -- cgit 1.2.3-korg