From owner-svn-src-all@FreeBSD.ORG Sat Jan 15 14:55:43 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 501E5106566B; Sat, 15 Jan 2011 14:55:43 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail02.syd.optusnet.com.au (mail02.syd.optusnet.com.au [211.29.132.183]) by mx1.freebsd.org (Postfix) with ESMTP id BF0308FC18; Sat, 15 Jan 2011 14:55:42 +0000 (UTC) Received: from c122-106-165-206.carlnfd1.nsw.optusnet.com.au (c122-106-165-206.carlnfd1.nsw.optusnet.com.au [122.106.165.206]) by mail02.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id p0FEtbFc015661 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 16 Jan 2011 01:55:40 +1100 Date: Sun, 16 Jan 2011 01:55:37 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Garrett Cooper In-Reply-To: Message-ID: <20110116013102.E21684@besplex.bde.org> References: <201101131820.p0DIKXip059402@svn.freebsd.org> <20110114174719.D28159@besplex.bde.org> <20110115133929.D16210@besplex.bde.org> <20110115170529.T16715@besplex.bde.org> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-1463948836-1295103337=:21684" Cc: svn-src-head@freebsd.org, mdf@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Bruce Evans Subject: Re: svn commit: r217369 - in head/sys: cam/scsi sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Jan 2011 14:55:43 -0000 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 wrot= e: >> On Fri, 14 Jan 2011, Garrett Cooper wrote: >> >>> On Fri, Jan 14, 2011 at 6:42 PM, Bruce Evans 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 > > 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--