Message ID | 20180611015119.94067-3-luc.vanoostenryck@gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On 11/06/18 02:51, Luc Van Oostenryck wrote: > The macros doing the list walking used to be done, not on the declared > list's type but on the concrete & generic type 'struct ptr_list'. > This incurs casting between the real and the generic type. > > Now that the declared type matches ... these casts are not needed > anymore and the real declared type can be used instead. > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> > --- > ptrlist.h | 26 +++++++++++++------------- > 1 file changed, 13 insertions(+), 13 deletions(-) > > diff --git a/ptrlist.h b/ptrlist.h > index 6cec720e0..4e985d45b 100644 > --- a/ptrlist.h > +++ b/ptrlist.h > @@ -98,7 +98,7 @@ static inline void *last_ptr_list(struct ptr_list *list) > } > > #define PTR_DEREF(__head, idx, PTR_ENTRY) ({ \ > - struct ptr_list *__list = __head; \ > + __typeof__(__head) __list = __head; \ > while (__list && __list->nr == 0) { \ > __list = __list->next; \ > if (__list == __head) \ > @@ -109,8 +109,8 @@ static inline void *last_ptr_list(struct ptr_list *list) > > #define DO_PREPARE(head, ptr, __head, __list, __nr, PTR_ENTRY) \ > do { \ > - struct ptr_list *__head = (struct ptr_list *) (head); \ > - struct ptr_list *__list = __head; \ > + __typeof__(head) __head = head; \ > + __typeof__(head) __list = head; \ Hmm, shouldn't this be: __typeof__(head) __list = __head; ? > int __nr = 0; \ > CHECK_TYPE(head,ptr); \ > ptr = PTR_DEREF(__head, 0, PTR_ENTRY); \ > @@ -155,8 +155,8 @@ static inline void *last_ptr_list(struct ptr_list *list) > DO_FINISH(ptr, __head##ptr, __list##ptr, __nr##ptr) > > #define DO_FOR_EACH(head, ptr, __head, __list, __nr, PTR_ENTRY) do { \ > - struct ptr_list *__head = (struct ptr_list *) (head); \ > - struct ptr_list *__list = __head; \ > + __typeof__(head) __head = head; \ > + __typeof__(head) __list = head; \ ditto. > CHECK_TYPE(head,ptr); \ > if (__head) { \ > do { int __nr; \ > @@ -176,8 +176,8 @@ static inline void *last_ptr_list(struct ptr_list *list) > } while (0) > > #define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr, PTR_ENTRY) do { \ > - struct ptr_list *__head = (struct ptr_list *) (head); \ > - struct ptr_list *__list = __head; \ > + __typeof__(head) __head = head; \ > + __typeof__(head) __list = head; \ ditto. [because of the long lines, these are somewhat hard to read!] ATB, Ramsay -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jun 12, 2018 at 04:00:37PM +0100, Ramsay Jones wrote: > On 11/06/18 02:51, Luc Van Oostenryck wrote: > > The macros doing the list walking used to be done, not on the declared > > list's type but on the concrete & generic type 'struct ptr_list'. > > This incurs casting between the real and the generic type. > > > > Now that the declared type matches ... these casts are not needed > > anymore and the real declared type can be used instead. > > > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> > > --- > > ptrlist.h | 26 +++++++++++++------------- > > 1 file changed, 13 insertions(+), 13 deletions(-) > > > > diff --git a/ptrlist.h b/ptrlist.h > > index 6cec720e0..4e985d45b 100644 > > --- a/ptrlist.h > > +++ b/ptrlist.h > > @@ -109,8 +109,8 @@ static inline void *last_ptr_list(struct ptr_list *list) > > > > #define DO_PREPARE(head, ptr, __head, __list, __nr, PTR_ENTRY) \ > > do { \ > > - struct ptr_list *__head = (struct ptr_list *) (head); \ > > - struct ptr_list *__list = __head; \ > > + __typeof__(head) __head = head; \ > > + __typeof__(head) __list = head; \ > > Hmm, shouldn't this be: __typeof__(head) __list = __head; ? Mmmm, yes, but only because head could have some side effects (but normally it's not the case). Thanks for noticing that. -- Luc -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/ptrlist.h b/ptrlist.h index 6cec720e0..4e985d45b 100644 --- a/ptrlist.h +++ b/ptrlist.h @@ -98,7 +98,7 @@ static inline void *last_ptr_list(struct ptr_list *list) } #define PTR_DEREF(__head, idx, PTR_ENTRY) ({ \ - struct ptr_list *__list = __head; \ + __typeof__(__head) __list = __head; \ while (__list && __list->nr == 0) { \ __list = __list->next; \ if (__list == __head) \ @@ -109,8 +109,8 @@ static inline void *last_ptr_list(struct ptr_list *list) #define DO_PREPARE(head, ptr, __head, __list, __nr, PTR_ENTRY) \ do { \ - struct ptr_list *__head = (struct ptr_list *) (head); \ - struct ptr_list *__list = __head; \ + __typeof__(head) __head = head; \ + __typeof__(head) __list = head; \ int __nr = 0; \ CHECK_TYPE(head,ptr); \ ptr = PTR_DEREF(__head, 0, PTR_ENTRY); \ @@ -155,8 +155,8 @@ static inline void *last_ptr_list(struct ptr_list *list) DO_FINISH(ptr, __head##ptr, __list##ptr, __nr##ptr) #define DO_FOR_EACH(head, ptr, __head, __list, __nr, PTR_ENTRY) do { \ - struct ptr_list *__head = (struct ptr_list *) (head); \ - struct ptr_list *__list = __head; \ + __typeof__(head) __head = head; \ + __typeof__(head) __list = head; \ CHECK_TYPE(head,ptr); \ if (__head) { \ do { int __nr; \ @@ -176,8 +176,8 @@ static inline void *last_ptr_list(struct ptr_list *list) } while (0) #define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr, PTR_ENTRY) do { \ - struct ptr_list *__head = (struct ptr_list *) (head); \ - struct ptr_list *__list = __head; \ + __typeof__(head) __head = head; \ + __typeof__(head) __list = head; \ CHECK_TYPE(head,ptr); \ if (__head) { \ do { int __nr; \ @@ -201,8 +201,8 @@ static inline void *last_ptr_list(struct ptr_list *list) #define DO_REVERSE(ptr, __head, __list, __nr, new, __newhead, \ __newlist, __newnr, PTR_ENTRY) do { \ - struct ptr_list *__newhead = __head; \ - struct ptr_list *__newlist = __list; \ + __typeof__(__head) __newhead = __head; \ + __typeof__(__head) __newlist = __list; \ int __newnr = __nr; \ new = ptr; \ goto __inside##new; \ @@ -247,7 +247,7 @@ static inline void *last_ptr_list(struct ptr_list *list) extern void split_ptr_list_head(struct ptr_list *); #define DO_SPLIT(ptr, __head, __list, __nr) do { \ - split_ptr_list_head(__list); \ + split_ptr_list_head((struct ptr_list*)__list); \ if (__nr >= __list->nr) { \ __nr -= __list->nr; \ __list = __list->next; \ @@ -255,7 +255,7 @@ extern void split_ptr_list_head(struct ptr_list *); } while (0) #define DO_INSERT_CURRENT(new, ptr, __head, __list, __nr) do { \ - void **__this, **__last; \ + TYPEOF(__head) __this, __last; \ if (__list->nr == LIST_NODE_NR) \ DO_SPLIT(ptr, __head, __list, __nr); \ __this = __list->list + __nr; \ @@ -272,8 +272,8 @@ extern void split_ptr_list_head(struct ptr_list *); DO_INSERT_CURRENT(new, ptr, __head##ptr, __list##ptr, __nr##ptr) #define DO_DELETE_CURRENT(ptr, __head, __list, __nr) do { \ - void **__this = __list->list + __nr; \ - void **__last = __list->list + __list->nr - 1; \ + TYPEOF(__head) __this = __list->list + __nr; \ + TYPEOF(__head) __last = __list->list + __list->nr - 1; \ while (__this < __last) { \ __this[0] = __this[1]; \ __this++; \
The macros doing the list walking used to be done, not on the declared list's type but on the concrete & generic type 'struct ptr_list'. This incurs casting between the real and the generic type. Now that the declared type matches ... these casts are not needed anymore and the real declared type can be used instead. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- ptrlist.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)