aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-02-08 00:46:01 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-02-08 00:46:01 +0100
commit89a73382b14904cd762529a79ca74e8c2b389dbc (patch)
tree20e19fa52330cd7e6e9c2aa4aa8c661225ac287c
parent60c1f2706e30eacc29296e6cb5d9327c85a01340 (diff)
downloadsparse-89a73382b14904cd762529a79ca74e8c2b389dbc.tar.gz
ptrlist: make ptr_list_nth_entry() generic with ptr_list_nth()
The library operation on pointer list necessarily act on the untyped version of the list. To use them with type checking, they must either be wrapped in inline function using the desired type or be used via some macro doing the type checking. Do this later solution for ptr_list_nth_entry(). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--ptrlist.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/ptrlist.h b/ptrlist.h
index 4bf8c709..c5fa4cdd 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -73,6 +73,10 @@ extern void __free_ptr_list(struct ptr_list **);
__free_ptr_list((struct ptr_list **)(list)); \
} while (0)
+#define ptr_list_nth(lst, nth) ({ \
+ struct ptr_list* head = (struct ptr_list*)(lst); \
+ (__typeof__((lst)->list[0])) ptr_list_nth_entry(head, nth);\
+ })
////////////////////////////////////////////////////////////////////////
// API