From 4fa296c3797b39d6cadc4b09ac4a3e79e4d3a578 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 15 Mar 2017 22:06:19 +0100 Subject: [PATCH] Port to M_TYPE_FROM_FIELD --- m-i-list.h | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/m-i-list.h b/m-i-list.h index f58c59a6..aba472b0 100644 --- a/m-i-list.h +++ b/m-i-list.h @@ -86,13 +86,6 @@ typedef struct ilist_head_s { POP(M_C3(ilist_,name,_pop_back)) \ ) -/* - * From a pointer to a 'field_type' 'field' of a 'type'structure, - * return pointer to the structure. - */ -#define ILISTI_TYPE_FROM_FIELD(type, ptr, field_type, field) \ - ((type *)(void*)( (char *)M_ASSIGN_CAST(field_type*, (ptr)) - offsetof(type, field) )) - #define ILISTI_DEF2(name, type, oplist) \ typedef struct M_C3(ilist_, name, _s) { \ struct ilist_head_s name; \ @@ -209,7 +202,7 @@ typedef struct ilist_head_s { M_C3(ilist_, name, _back)(const M_C3(ilist_, name,_t) list) \ { \ assert(list != NULL && !M_C3(ilist_, name, _empty_p)(list)); \ - return ILISTI_TYPE_FROM_FIELD(type, list->name.prev, \ + return M_TYPE_FROM_FIELD(type, list->name.prev, \ struct ilist_head_s, name); \ } \ \ @@ -217,7 +210,7 @@ typedef struct ilist_head_s { M_C3(ilist_, name, _front)(const M_C3(ilist_, name,_t) list) \ { \ assert(list != NULL && !M_C3(ilist_, name, _empty_p)(list)); \ - return ILISTI_TYPE_FROM_FIELD(type, list->name.next, \ + return M_TYPE_FROM_FIELD(type, list->name.next, \ struct ilist_head_s, name); \ } \ \ @@ -324,7 +317,7 @@ typedef struct ilist_head_s { assert (it->current->next == it->next); \ assert (it->current->prev == it->previous); \ assert (!M_C3(ilist_, name, _end_p)(it)); \ - return ILISTI_TYPE_FROM_FIELD(type, it->current, \ + return M_TYPE_FROM_FIELD(type, it->current, \ struct ilist_head_s, name); \ } \ \