aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-12-29 17:51:03 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-03-06 22:57:27 +0100
commit6bd31037f468ca68c1fea5463d8ff786618467cd (patch)
tree7f19b701f373dd5c488959523e74eddd765655f7
parentf909765ac1e826b7360775438c34f5401e80fca0 (diff)
downloadsparse-6bd31037f468ca68c1fea5463d8ff786618467cd.tar.gz
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 <luc.vanoostenryck@gmail.com>
-rw-r--r--ptrlist.h6
1 files changed, 6 insertions, 0 deletions
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)); \