Re: #include struct.h in sys/queue.h
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 [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: #include struct.h in sys/queue.h
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 dev/sym/sym_hipd.c, line 347 i386/i386/machdep.c, line 246 kern/sysv_sem.c, line 110 kern/uipc_usrreq.c, line 548 netinet/ip_compat.h, line 56 netinet/ip_fil.h, line 254 netinet6/icmp6.c, line 761 netinet6/in6_proto.c, line 126 netinet6/raw_ip6.c, line 348 pc98/i386/machdep.c, line 254 If we unify it in one header file, I'd be happy to use that for STAILQ_LAST(). 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? To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: #include struct.h in sys/queue.h
Hi, On Mon, Oct 02, 2000 at 12:06:18PM +0200, Poul-Henning Kamp wrote: This is because there is a file called "struct.h" in the ircII distribution. The addition of #include struct.h to sys/queue.h looks a bit unsettling to me: A sys/* file shouldn't reference a /usr/include file I think ? Is the correct thing not to mv struct.h to sys/struct.h, create a struct.h which just pulls in sys/struct.h and have sys/queue.h #include sys/struct.h ? This breaks several other ports (like BitchX). -Jeremy -- FreeBSD - Because the best things in life are free... http://www.freebsd.org/ To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: #include struct.h in sys/queue.h
In message [EMAIL PROTECTED], Jeremy Lea writes: Is the correct thing not to mv struct.h to sys/struct.h, create a struct.h which just pulls in sys/struct.h and have sys/queue.h #include sys/struct.h ? This breaks several other ports (like BitchX). I think this breaks all IRC's which are cloned from the same origin :-) -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 [EMAIL PROTECTED] | TCP/IP since RFC 956 FreeBSD coreteam member | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: #include struct.h in sys/queue.h
This breaks several other ports (like BitchX). I think this breaks all IRC's which are cloned from the same origin :-) I'm still looking for the downside to this. ;-) - Jordan To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: #include struct.h in sys/queue.h
On Mon, Oct 02, 2000 at 10:10:39AM -0700, Jordan Hubbard wrote: This breaks several other ports (like BitchX). I think this breaks all IRC's which are cloned from the same origin :-) I'm still looking for the downside to this. ;-) 'HEY!' ;P Greetz, Peter -- dataloss networks '/ignore-ance is bliss' - me To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: #include struct.h in sys/queue.h
On Mon, 2 Oct 2000, Jordan Hubbard wrote: This breaks several other ports (like BitchX). I think this breaks all IRC's which are cloned from the same origin :-) I'm still looking for the downside to this. ;-) Well *some* of us still use ircII, however I've successfully compiled such under -current, but yes, I needed to do a little work :p -trish __ Trish Lynch FreeBSD - The Power to Serve[EMAIL PROTECTED] Rush Networking [EMAIL PROTECTED] VA Linux Systems[EMAIL PROTECTED] O|S|D|N [EMAIL PROTECTED] --- "how long till my soul gets it right can any human being ever reach that kind of light i call on the resting soul of galileo king of night vision, king of insight" -Indigo Girls, Galileo To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: #include struct.h in sys/queue.h
On Mon, 2 Oct 2000, Poul-Henning Kamp wrote: Trying to compile the ircII port, it crashes with: === Building for ircii-4.4X cc -I. -I/usr/ports/irc/ircII/work/ircii-4.4X/include -O -pipe -DHAVE_CONFIG_H -c /usr/ports/irc/ircII/work/ircii-4.4X/source/alias.c In file included from /usr/include/sys/queue.h:40, from /usr/include/netinet6/in6.h:76, from /usr/include/netinet/in.h:475, from /usr/ports/irc/ircII/work/ircii-4.4X/include/irc.h:79, from /usr/ports/irc/ircII/work/ircii-4.4X/source/alias.c:35: /usr/ports/irc/ircII/work/ircii-4.4X/include/struct.h:51: syntax error before `_' This is because there is a file called "struct.h" in the ircII distribution. The addition of #include struct.h to sys/queue.h looks a bit unsettling to me: A sys/* file shouldn't reference a /usr/include file I think ? I corresponded with the author of this bug soon after it was committed, but didn't follow up. Is the correct thing not to mv struct.h to sys/struct.h, create a struct.h which just pulls in sys/struct.h and have sys/queue.h #include sys/struct.h ? Of course not. Just expand the one macro that is used (strbase()) in the one place that it is used in sys/queue.h. I think struct.h should have been removed when offsetof() became standard. It was only used in one place in /usr/src (lastcomm). Only the fldsiz() macro is used there. struct.h defines 2 other macros: fldoff() and strbase(). fldoff() is a bad version of offsetof() (one that takes a struct tag instead of a type, so it can't be used with typedefed structs). 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. Bruce To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message