minor cleanup of type-checking for ptrlist.h
RFC PATCH 1/1 minor cleanup of type-checking for ptrlist.h
DECLARE_PTR_LIST and friends are for 'Silly type-safety check'. The member (type *list[1]) of strust listname is never directly dereferenced or used except for CHECK_TYPE things. So why was it made an array of pointer instead of simply a pointer? IMHO, it gives no benefits but complicates things a bit. Or am i missing something?
This patch just change the array of pointer to a pointer.
Signed-off-by Alecs King <[email protected]>
dissect.c +3 -3
@@ -14,7 +14,7 @@#define DO_LIST (l__, p__, expr__) \ do { \ - typeof(l__->list[0]) p__; \ + typeof(l__->list) p__; \ FOR_EACH_PTR(l__, p__) \ expr__; \ END_FOR_EACH_PTR(p__); \
@@ -22,8 +22,8 @@#define DO_2_LIST (l1__,l2__, p1__,p2__, expr__) \ do { \ - typeof(l1__->list[0]) p1__; \ - typeof(l2__->list[0]) p2__; \ + typeof(l1__->list) p1__; \ + typeof(l2__->list) p2__; \ PREPARE_PTR_LIST(l1__, p1__); \ FOR_EACH_PTR(l2__, p2__) \ expr__; \
ptrlist.h +4 -4
@@ -11,10 +11,10 @@ (type *)((void *)(ptr) - offsetof(type , member)) /* Silly type-safety check ;) */ -#define DECLARE_PTR_LIST (listname,type) struct listname { type *list[1]; } -#define CHECK_TYPE (head,ptr) (void)(&(ptr) == &(head)->list[0]) -#define TYPEOF (head) __typeof__(&(head)->list[0]) -#define VRFY_PTR_LIST (head) (void)(sizeof((head)->list[0])) +#define DECLARE_PTR_LIST (listname,type) struct listname { type *list; } +#define CHECK_TYPE (head,ptr) (void)(&(ptr) == &(head)->list) +#define TYPEOF (head) __typeof__(&(head)->list) +#define VRFY_PTR_LIST (head) (void)(sizeof((head)->list))#define LIST_NODE_NR (29)
Signature · 1 line
Alecs King