On Sat, 15 Jan 2011, Garrett Cooper wrote:

On Fri, Jan 14, 2011 at 10:27 PM, Bruce Evans <b...@optusnet.com.au> wrote:
On Fri, 14 Jan 2011, Garrett Cooper wrote:

On Fri, Jan 14, 2011 at 6:42 PM, Bruce Evans <b...@optusnet.com.au> wrote:

...
Oops. ?I think sizeof() and issigned() can be used to determine the type
well enough in functions and initialized data (do a fuller type check if
the compiler supports it), but I don't know how to do this in static
sysctl declarations (since sizeof() can't be used in cpp expressions).

? Why not just create some dumb testcases that can be run at build
time to determine that for you?

Well, how? ?You are given SYSCTL_I(&var, ...) and have to convert this
to what is now in SYSCTL_INT(), using only the type of var, in hundreds
or thousands of files. ?I don't even know how to do this with a test
...

? ? ? ?/* Only works for arithmetic types: */
? ? ? ?#define isinteger(var) ?((typeof(var))0.1 == 0)
? ? ? ?#define issigned(var) ? ((typeof(var))-1 < 0)
? ? ? ?...

   This is what I meant:

$ cat test_warnings.c
#include <sys/types.h>

size_t x = (int) -1;
int y = 20000000000L;
$ gcc -Wconversion -Wstrict-overflow -Wsign-compare -c test_warnings.c
test_size_t.c:3: warning: negative integer implicitly converted to unsigned type
test_size_t.c:4: warning: overflow in implicit constant conversion
$

   With the right CFLAGS and a few properly written tests, and a few
make rules, you can figure out what's what pretty easily *shrugs*.

That's a lot more parsing than seems reasonable.

Anyway, we already depend on gnu __typeof() being avaible for the much
more central API of pcpu.  All pcpu accesses on amd64 and i386 use it,
except curthread (curthread has been hacked to use a more direct asm
for compile-time efficiency).

SYSCTL_I() works even better that I first thought.  It automatically
gives support for all typedefed integral types.  No SYSCTL_FOO_T()s
with messy MD ifdefs for matching up foo_t with an integral type are
needed.  Instead there are even messier MI ifdefs in SYSCTL_I() :-).
But not so many.  There are hundreds of typedefed types of interest,
but only 8 different integer types to map to (8/16/32/64 bits signed
and unsigned).  The complication that int64_t is plain long on 64
bit arches but long long on 32-bit arches still arises.  CTLTYPE_QUAD
can be associated with int64_t on all arches, but the format for printing
these is arch-dependent.  (Note that quad_t's cannot be printed using
%qd, and %qd is unusable, since %qd is just an alias for %lld, while
quad_t is an alias for int64_t and int64_t is plain long on 64-bit
arches so its format is %ld on these arches and %lld on others.)

Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to