Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Oct 2009 08:37:58 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Lawrence Stewart <lstewart@freebsd.org>
Cc:        svn-src-projects@freebsd.org, src-committers@freebsd.org, Bruce Evans <brde@optusnet.com.au>
Subject:   Re: svn commit: r197638 - projects/tcp_ffcaia2008_8.x/sys/kern
Message-ID:  <20091001070833.R49077@besplex.bde.org>
In-Reply-To: <4AC3A7CE.4000207@freebsd.org>
References:  <200909300953.n8U9r3Oo011112@svn.freebsd.org> <20090930203736.D1368@besplex.bde.org> <4AC3A7CE.4000207@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 30 Sep 2009, Lawrence Stewart wrote:

> Bruce Evans wrote:
>> <sys/systm.h> should not be sorted alphabeticaly, since it declares
>> things like KASSERT() and (by nested includes) hundreds of inline
>> functions (especially ones in <machine/atomic.h>, <machine/cpufunc.h>
>> and <sys/libkern.h>) which are used in many other headers.  It should
>> be sorted immediately after <sys/param.h> where it was.
>
> Ok got it, thanks for the pointer. Everything compiled fine which is why I 
> made the change but as you say there must be some "pollution" somewhere. Does 
> this requirement to keep the systm.h include up top warrant a mention in 
> style(9) or is it just something to remember?

It's not really style, but how the kernel headers are (dis)organized.
mumble(9) would be a better place.  Probably intro(9), except that doesn't
exist.

> Random, likely naive thought: is there some way to detect if a header has 
> been included before or after another header? Could be done fairly easily 
> with an external script I guess,

cpp -M order (used in .depend files) gives the order of include processing.
This could be used in the script.  I sometimes look at .depend files to
find header pollution, but haven't automated this.

> but something explicit in the files (some 
> sort of preprocessor and macro magic?) would be more useful I suspect. 
> Perhaps there could be a warning emitted if ordering is violated or an 
> include is detected that shouldn't be there. If done right, it would likely 
> do the job of educating people about correct ordering/inclusion and go a long 
> way to reducing "pollution creep".

Generally we're trying to reduce prerequisites by including headers
in other headers, but this is hard to do without increasing the include
mess, and almost everything still has <sys/types.h> and probably
<sys/param.h> and possibly <sys/systm.h> as prerequisites.

I don't know how to detect pollution using only standard C cpp directives.
It would be easy using counters as found in primitive macro assemblers,
but cpp still doesn't seem to have anything like that.

I just looked at cpp.info and found the nonstandard __INCLUDE_LEVEL__
directive which could be used to set a boolean macro when a header is
included non-nested.  Unfortunately, cpp is also missing the feature
of directives within directives (also found in primitive macro assembler)
which would be useful here for avoiding having to change every header
of interest to set the new macro.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20091001070833.R49077>