From owner-svn-src-head@freebsd.org Tue Mar 15 09:23:25 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DB15DAD1FE6; Tue, 15 Mar 2016 09:23:25 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail109.syd.optusnet.com.au (mail109.syd.optusnet.com.au [211.29.132.80]) by mx1.freebsd.org (Postfix) with ESMTP id A01D2DD0; Tue, 15 Mar 2016 09:23:25 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c110-21-41-193.carlnfd1.nsw.optusnet.com.au (c110-21-41-193.carlnfd1.nsw.optusnet.com.au [110.21.41.193]) by mail109.syd.optusnet.com.au (Postfix) with ESMTPS id A125FD6778E; Tue, 15 Mar 2016 20:04:23 +1100 (AEDT) Date: Tue, 15 Mar 2016 20:04:22 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Hans Petter Selasky cc: Gleb Smirnoff , Ryan Stone , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Subject: Re: svn commit: r296868 - head/sys/sys In-Reply-To: <56E7BD28.2000606@selasky.org> Message-ID: <20160315192238.B1463@besplex.bde.org> References: <201603141807.u2EI7xqm075602@repo.freebsd.org> <20160314203318.GL1328@FreeBSD.org> <56E7BD28.2000606@selasky.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=KvuwojiN c=1 sm=1 tr=0 a=73JWPhLeruqQCjN69UNZtQ==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=6I5d2MoRAAAA:8 a=WNfKXsEaDt8PeAfE1v8A:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Mar 2016 09:23:26 -0000 On Tue, 15 Mar 2016, Hans Petter Selasky wrote: > On 03/14/16 21:33, Gleb Smirnoff wrote: >> On Mon, Mar 14, 2016 at 02:31:37PM -0400, Ryan Stone wrote: >> R> On Mon, Mar 14, 2016 at 2:07 PM, Gleb Smirnoff >> wrote: >> R> >> R> > Remove useless cast in SYSCTL_ADD_COUNTER_U64 macro. There was no cast here. >> R> Is it useless? I believe that the point is to give a compiler error if >> an >> R> incompatible pointer type was passed as the ptr parameter. >> >> Thanks for explanation! I will back out. > > I added the casts to get more checks with regard to the type safety in the > sysctls, because sysctl_add_oid() uses "void *". They are not useless. Casts would reduce type safety. You actually added assignments. Assignments to void * would be little different from conversions to the void * parameter, but the assignments are to uint64_t * so they detect most type differences except an initial type of void * which might be correct (the caller should have started with uint64_t *, and it is too late to detect the error if the caller started with something like const volatile int32_t * and subverted this to void *. But if the sysctl is read-only, subverting its pointer from const int64_t * to int64_t * might be needed since lower levels don't support const). > Maybe this should be explained in a comment somewhere? A comment is not a place to explain what a cast is. The assignment doesn't work for what should the usual case of a static initializer. I don't see a good way to fix this. A not so good way is to add a union holding int *, long *, etc. to the sysctl data. Then for SYSCTL_INT() assign the pointer to the the int * union member, etc. Bruce