atom feed9 messages in org.freebsd.freebsd-currentRe: #include <struct.h> in <sys/queue.h>
FromSent OnAttachments
Poul-Henning KampOct 2, 2000 3:05 am 
Jeremy LeaOct 2, 2000 3:14 am 
Poul-Henning KampOct 2, 2000 3:20 am 
Jordan HubbardOct 2, 2000 10:10 am 
Peter van DijkOct 2, 2000 10:52 am 
Siobhan Patricia LynchOct 2, 2000 6:41 pm 
Bruce EvansOct 2, 2000 7:45 pm 
Jeffrey HsuOct 3, 2000 1:07 am 
Bruce EvansOct 5, 2000 4:03 am 
Subject:Re: #include <struct.h> in <sys/queue.h>
From:Bruce Evans (bd@zeta.org.au)
Date:Oct 5, 2000 4:03:25 am
List:org.freebsd.freebsd-current

On Tue, 3 Oct 2000, Jeffrey Hsu wrote:

> I think <struct.h> 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 <stddef.h>.

If we unify it in one header file, I'd be happy to use that for STAILQ_LAST().

<machine/ansi.h> is a good place for it now.

> strbase() is now used in <sys/queue.h>. It is > easy to implement directly using offsetof(). Unfortunately, if it is > implemented using offsetof(), then <sys/queue.h> will depend on > <stddef.h>.

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 <struct.h> - /* * 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 + * <stddef.h> and strbase() in <struct.h>. + */ + #include <machine/ansi.h> + + #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 majo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message