Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Jan 2011 01:55:37 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Garrett Cooper <gcooper@freebsd.org>
Cc:        svn-src-head@freebsd.org, mdf@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Bruce Evans <brde@optusnet.com.au>
Subject:   Re: svn commit: r217369 - in head/sys: cam/scsi sys
Message-ID:  <20110116013102.E21684@besplex.bde.org>
In-Reply-To: <AANLkTimoT9c6q2=K=C7dSnxJXkT=qZx=wPbAf6k68hWZ@mail.gmail.com>
References:  <201101131820.p0DIKXip059402@svn.freebsd.org> <AANLkTinh619WaGgq=5fFxTvEX0JPir34k8xb%2Bs6oSH8Y@mail.gmail.com> <20110114174719.D28159@besplex.bde.org> <AANLkTikVwuSO3h8tKeYXCvC6zqYVHVxdY5Abrzo-Ks2R@mail.gmail.com> <20110115133929.D16210@besplex.bde.org> <AANLkTi=B5mZCJ_bhe=Gf1pLUmWsTswi3O3U2ZLnHMODV@mail.gmail.com> <20110115170529.T16715@besplex.bde.org> <AANLkTimoT9c6q2=K=C7dSnxJXkT=qZx=wPbAf6k68hWZ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--0-1463948836-1295103337=:21684
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

On Sat, 15 Jan 2011, Garrett Cooper wrote:

> On Fri, Jan 14, 2011 at 10:27 PM, Bruce Evans <brde@optusnet.com.au> wrot=
e:
>> On Fri, 14 Jan 2011, Garrett Cooper wrote:
>>
>>> On Fri, Jan 14, 2011 at 6:42 PM, Bruce Evans <brde@optusnet.com.au> wro=
te:

>>>> ...
>>>> Oops. =A0I 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).
>>>
>>> =A0 Why not just create some dumb testcases that can be run at build
>>> time to determine that for you?
>>
>> Well, how? =A0You 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. =A0I don't even know how to do this with a test
>> ...
>>
>> =A0 =A0 =A0 =A0/* Only works for arithmetic types: */
>> =A0 =A0 =A0 =A0#define isinteger(var) =A0((typeof(var))0.1 =3D=3D 0)
>> =A0 =A0 =A0 =A0#define issigned(var) =A0 ((typeof(var))-1 < 0)
>> =A0 =A0 =A0 =A0...
>
>    This is what I meant:
>
> $ cat test_warnings.c
> #include <sys/types.h>
>
> size_t x =3D (int) -1;
> int y =3D 20000000000L;
> $ gcc -Wconversion -Wstrict-overflow -Wsign-compare -c test_warnings.c
> test_size_t.c:3: warning: negative integer implicitly converted to unsign=
ed 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
--0-1463948836-1295103337=:21684--



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