From 65ba173dea53ef47288f95aecf8642ac9869181f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 27 Apr 2010 17:47:38 +0100 Subject: [PATCH 1/1] Get rid of type aliasing --- backends/innduct.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/backends/innduct.c b/backends/innduct.c index 4311dca..8e5181a 100644 --- a/backends/innduct.c +++ b/backends/innduct.c @@ -205,26 +205,29 @@ perl -ne 'print if m/-8\<-/..m/-\>8-/; print "\f" if m/-\^L-/' backends/innduct. /*----- doubly linked lists -----*/ -#define ISNODE(T) struct { T *succ, *pred; } node /* must be at start */ -#define DEFLIST(T) typedef struct { T *hd, *tl, *tp; int count; } T##List +#define ISNODE(T) struct node list_node +#define DEFLIST(T) \ + typedef struct { \ + union { struct list li; T *for_type; } u; \ + int count; \ + } T##List -#define NODE(n) (assert((void*)&(n)->node == &(n)), \ - (struct node*)&(n)->node) +#define NODE(n) (assert((void*)&(n)->list_node == &(n)), &(n)->list_node) #define LIST_CHECKCANHAVENODE(l,n) \ - ((void)((n) == ((l).hd))) /* just for the type check */ + ((void)((n) == ((l).u.for_type))) /* just for the type check */ -#define LIST_ADDSOMEHOW(l,n,list_addsomehow) \ - ( LIST_CHECKCANHAVENODE(l,n), \ - list_addsomehow((struct list*)&(l), NODE((n))), \ - (void)(l).count++ \ +#define LIST_ADDSOMEHOW(l,n,list_addsomehow) \ + ( LIST_CHECKCANHAVENODE(l,n), \ + list_addsomehow(&(l).u.li, NODE((n))), \ + (void)(l).count++ \ ) #define LIST_REMSOMEHOW(l,list_remsomehow) \ - ( (typeof((l).hd)) \ + ( (typeof((l).u.for_type)) \ ( (l).count \ ? ( (l).count--, \ - list_remsomehow((struct list*)&(l)) ) \ + list_remsomehow(&(l).u.li) ) \ : 0 \ ) \ ) @@ -235,8 +238,8 @@ perl -ne 'print if m/-8\<-/..m/-\>8-/; print "\f" if m/-\^L-/' backends/innduct. #define LIST_REMHEAD(l) LIST_REMSOMEHOW((l),list_remhead) #define LIST_REMTAIL(l) LIST_REMSOMEHOW((l),list_remtail) -#define LIST_INIT(l) ((l).hd, list_new((struct list*)&(l))) -#define LIST_HEAD(l) ((typeof((l).hd))(list_head((struct list*)&(l)))) +#define LIST_INIT(l) (list_new(&(l).u.li)) +#define LIST_HEAD(l) ((typeof((l).u.for_type))(list_head((struct list*)&(l)))) #define LIST_NEXT(n) ((typeof(n))list_succ(NODE((n)))) #define LIST_BACK(n) ((typeof(n))list_pred(NODE((n)))) -- 2.30.2