From owner-svn-src-all@FreeBSD.ORG Sat Jan 15 08:45:17 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 066B5106564A; Sat, 15 Jan 2011 08:45:17 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 1816A8FC13; Sat, 15 Jan 2011 08:45:15 +0000 (UTC) Received: by wwf26 with SMTP id 26so3721741wwf.31 for ; Sat, 15 Jan 2011 00:45:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=li65pVSoKmjg3Md4cqXgMAsiSh4qZwTRwEe4xZp+QIc=; b=O4qdQszPq4Gn9zzLOoMRDSDUuhlstO20LmiNhKnRwn+JS5OA1pVflLgUBX9x5tClZb dGnOn1LU7d8N9jSEO1kZ2zipxAIVigw1RRY4/YRzt8f0EHKZk30zpwVLgF5bKIoUc8Z4 Lry/GZp99shmhCcS44LHPTOqHN/x9pj6/Yeiw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=tMttd0JEnmC7ki8FRR5WG73Uzq+wiEaNaU991IqgcBmEryPSi51UOtHrzFfAzwuo22 19qLsf2gtBjfmTiICh2vRu45dnHDHEK+lIUzZQT3ITFTDX5UzmShSQV/Np+xcOAuW1mG TARiBeRjbyd1l5ejw8/714WaSrE8+o9hzunxs= MIME-Version: 1.0 Received: by 10.216.78.146 with SMTP id g18mr1453076wee.1.1295081114636; Sat, 15 Jan 2011 00:45:14 -0800 (PST) Sender: yanegomi@gmail.com Received: by 10.216.254.226 with HTTP; Sat, 15 Jan 2011 00:45:14 -0800 (PST) In-Reply-To: <20110115170529.T16715@besplex.bde.org> References: <201101131820.p0DIKXip059402@svn.freebsd.org> <20110114174719.D28159@besplex.bde.org> <20110115133929.D16210@besplex.bde.org> <20110115170529.T16715@besplex.bde.org> Date: Sat, 15 Jan 2011 00:45:14 -0800 X-Google-Sender-Auth: pjKfM8A0hd090s-NvEUlcrazLBc Message-ID: From: Garrett Cooper To: Bruce Evans Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@freebsd.org, mdf@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org 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 08:45:17 -0000 On Fri, Jan 14, 2011 at 10:27 PM, Bruce Evans wrote: > On Fri, 14 Jan 2011, Garrett Cooper wrote: > >> On Fri, Jan 14, 2011 at 6:42 PM, Bruce Evans wrot= e: >>> >>> On Fri, 14 Jan 2011 mdf@FreeBSD.org wrote: >>> >>>> On Thu, Jan 13, 2011 at 10:50 PM, Bruce Evans >>>> wrote: >>>>> >>>>> On Thu, 13 Jan 2011 mdf@freebsd.org wrote: >>>>> >>>>>> There appear to be 330 uses of SYSCTL and QUAD on the same line in >>>>>> CURRENT. =A0This seems reasonable to change them to S64, U64 and X64= so >>>>>> they correctly reflect the size they operate upon. >>>>>> >>>>>> What do y'all think? >>>>> >>>>> Now I suggest delaying this until they can be renamed to a type- >>>>> generic >>>>> SYSCTL_INT() (would probably need to be spelled differently, SYSCTL_I= () >>>>> say, even if SYSCTL_INT() was changed at the same time). >>>> >>>> I'm torn on this one. =A0The compiler knows the type (unless, for >>>> SYSCTL_INT, NULL/0 is used, but that is also a compile-time check), >>>> but to interpret it requires the use of __builtin_foo which is a gcc >>>> extension and not part of standard C. >>>> >>>> Philosophically, while I like this kind of letting the compiler do the >>>> work, if you want C++ you know where to find it. >>> >>> Oops. =A0I think sizeof() and issigned() can be used to determine the t= ype >>> well enough in functions and initialized data (do a fuller type check i= f >>> 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 > case for each file, short of parsing all the files. =A0Oops, I do know > how to translate from sizeof(var) to CTLTYPE_INT or CTLTYPE_UINT. > That's just (sizeof(var) =3D=3D sizeof(int) ? CTLTYPE_INT : ...). =A0The > signness is harder (might need gnu typeof(), but not the recent type > checking attributes). =A0This won't convert from SYSCTL_I() existing > SYSCTL_INT() (the switch on the size would have to be in an ifdef for > that, but sizeof() doesn't work in ifdefs), but it works for generating > CTLTYPE_* internally SYSCTL_I(). =A0The difficulty is converting from a > bare variable `var' to an integer representing the signedness of its > type, without using an unportability like typeof(). =A0With typeof(), thi= s > is: > > =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 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*. Thanks, -Garrett