From owner-freebsd-current Thu Oct 5 4: 4: 1 2000 Delivered-To: freebsd-current@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 9647F37B502; Thu, 5 Oct 2000 04:03:56 -0700 (PDT) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.8.7/8.8.7) with ESMTP id WAA20933; Thu, 5 Oct 2000 22:03:52 +1100 Date: Thu, 5 Oct 2000 22:03:47 +1100 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Jeffrey Hsu Cc: current@FreeBSD.ORG Subject: Re: #include in In-Reply-To: <20001003080816.9D03137B502@hub.freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 3 Oct 2000, Jeffrey Hsu wrote: > > I think should have been removed when offsetof() became > > standard. > > At last count, offsetof() is defined in 11 different places in the kernel: > alpha/alpha/machdep.c, line 234 >... Some other places include . > If we unify it in one header file, I'd be happy to use that for STAILQ_LAST(). is a good place for it now. > > strbase() is now used in . It is > > easy to implement directly using offsetof(). Unfortunately, if it is > > implemented using offsetof(), then will depend on > > . > > So, what's the correct solution? I'm currently using the following. This avoids a bug in fldoff(): casting to int is wrong and causes warnings on alphas. I use a cast to __uintptr_t since casting to size_t is normally right (offsetof() depends on it), and __uintptr_t is normally equivalent to size_t and is easier to get at. --- diff -c2 queue.h~ queue.h *** queue.h~ Fri Aug 4 21:38:55 2000 --- queue.h Thu Oct 5 21:22:51 2000 *************** *** 38,43 **** #define _SYS_QUEUE_H_ - #include - /* * This file defines five types of data structures: singly-linked lists, --- 38,41 ---- *************** *** 224,231 **** } while (0) #define STAILQ_LAST(head, type, field) \ ! (STAILQ_EMPTY(head) ? \ ! NULL : \ ! strbase(type, (head)->stqh_last, field)) #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) --- 222,239 ---- } while (0) + /* + * XXX auxiliary macros for STAILQ_LAST() adapted from offsetof() in + * and strbase() in . + */ + #include + + #define __offsetof(type, member) \ + ((__uintptr_t)(&((type *)0)->member)) + #define __strbase(name, addr, field) \ + ((struct name *)((char *)(addr) - __offsetof(struct name, field))) + #define STAILQ_LAST(head, type, field) \ ! (STAILQ_EMPTY(head) ? NULL : \ ! __strbase(type, (head)->stqh_last, field)) #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) --- Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message