From owner-freebsd-arch@FreeBSD.ORG Tue Sep 9 08:33:40 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2793EAC4 for ; Tue, 9 Sep 2014 08:33:40 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BE18E298 for ; Tue, 9 Sep 2014 08:33:39 +0000 (UTC) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id s898XX0t073396 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 9 Sep 2014 11:33:33 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua s898XX0t073396 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id s898XXQM073395; Tue, 9 Sep 2014 11:33:33 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 9 Sep 2014 11:33:33 +0300 From: Konstantin Belousov To: yaneurabeya@gmail.com Subject: Re: [RFC] Add __arraycount from NetBSD to sys/cdefs.h Message-ID: <20140909083333.GA2737@kib.kiev.ua> References: <8D279BDC-7D40-4750-8DA7-A4535DD2E458@bsdimp.com> <146C3E96-7461-4D30-8B7F-5E20F72CF061@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="RJWZ9TQ7tP81YmMW" Content-Disposition: inline In-Reply-To: <146C3E96-7461-4D30-8B7F-5E20F72CF061@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: "freebsd-arch@FreeBSD.org Arch" X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Sep 2014 08:33:40 -0000 --RJWZ9TQ7tP81YmMW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Sep 08, 2014 at 09:29:54AM -0700, yaneurabeya@gmail.com wrote: > On Sep 3, 2014, at 21:17, Warner Losh wrote: >=20 > > On Sep 3, 2014, at 9:45 PM, Garrett Cooper wrot= e: > >=20 > >> Hi all, > >> In order to ease porting code and reduce divergence with NetBSD > >> when importing code (a large chunk of which for me are tests), I would > >> like to move nitems to sys/cdefs.h and alias __arraycount to nitems. > >> Here's the __arraycount #define in lib/libnetbsd/sys/cdefs.h: > >>=20 > >> 44 /* > >> 45 * Return the number of elements in a statically-allocated array, > >> 46 * __x. > >> 47 */ > >> 48 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) > >>=20 > >> Here's the nitems #define in sys/sys/param.h: > >>=20 > >> 277 #define nitems(x) (sizeof((x)) / sizeof((x)[0])) > >>=20 > >> sys/cdefs.h gets pulled in automatically with sys/param.h, so > >> anything using nitems will continue to function like before (see below > >> for more details). I've attached a patch which addresses all hardcoded > >> definitions in the tree added by FreeBSD developers. > >> If there aren't any major concerns with my proposed change, I'll > >> put it up for review on Phabricator. > >> Thank you! > >> -Garrett > >>=20 > >> $ cat cdefs_pound_define.c > >> #include > >>=20 > >> #ifdef _SYS_CDEFS_H_ > >> #warning "sys/cdefs.h has been included" > >> #endif > >> $ cc -c cdefs_pound_define.c > >> cdefs_pound_define.c:4:2: warning: "sys/cdefs.h has been included" [-W= #warnings] > >> #warning "sys/cdefs.h has been included" > >> ^ > >> 1 warning generated. > >> $ cc -D_KERNEL -c cdefs_pound_define.c > >> cdefs_pound_define.c:4:2: warning: "sys/cdefs.h has been included" [-W= #warnings] > >> #warning "sys/cdefs.h has been included" > >> ^ > >> 1 warning generated. > >> $ gcc -c cdefs_pound_define.c > >> cdefs_pound_define.c:4:2: warning: #warning "sys/cdefs.h has been incl= uded" > >> $ gcc -D_KERNEL -c cdefs_pound_define.c > >> cdefs_pound_define.c:4:2: warning: #warning "sys/cdefs.h has been incl= uded? > >=20 > > I wouldn?t bother changing the nitems #define. There?s no need, really,= to do that. >=20 > Rethinking my proposal, I agree. I had lofty hopes for unifying the macro= s, but the functional duplication (1 line) is harmless. >=20 > > I?d also be more inclined to believe the test if you tested what the th= ing does rather than test for an artificial, implementation defined side ef= fect. >=20 > Sure. I provided a lazy proof instead of a full proof :). >=20 > > But honestly the amount of duplication saved here is rather tiny? >=20 > Indeed! Thank you for the input :) ? I?ve attached a new patch which does= n?t disturb nitems or sys/param.h. Since this is seriously discussed on arch@, I think it is worth look at the following: git grep -e 'sizeof.*/sizeof' -- | grep -v '^contrib' | grep '#.*define' | = wc -l 118 These are only defines, not uses, not counting direct use of sizeof(x)/sizeof(x[0]) in the code. Not all of them are for equiv macros, but significant part repeats ntimes() in variations. At least Linuxish ARRAY_SIZE/DRM_ARRAY_SIZE is much more popular than __arraysize() which appears three (!) times. I do not see any reason to pollute central header cdefs.h with sparcely used macro for some compat code. --RJWZ9TQ7tP81YmMW Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJUDrtdAAoJEJDCuSvBvK1BN4cQAJHrDO928nZq4p0WUfrGjj/N cCekP+TnQxuaBn8sm6fEuoff9ZF/eh48s/0/i+ULNwrY085OZfmhvczeTP9Xj+kh Lm2MDKY3uLeQRLPtG+2KLd7ROH8M4oGM0Md7kuBgsr+uQ5kV7zEkHXyiBcbVqgDy Sj2Fe+j88BiHwfGM8iWSNoQQze9zNYjpqADg/TlPUlCkxNlZp3YR1CWTajePYhiY faf5QO7JPLulQOzabezfLKi5SYh6l0lVhDD6/+pkXibCpX8hemeeRR5zB3ccuSMs Ba0ZPOLG9gysZFGHYUSOw4KnzJp8Un1um9HVhr98NqZ299LLgG6AwjSAXRi1/Ui3 ZwMqHkmorxQ/jE1+4zDISGfH28JEXSvxIWVVMPCnJ9iFvoQImjouunPCRsogR3e4 4vBX03MifrxszprVRsPfhCTX45htX+ip23iietx9ojuYcK1bxUjRtYW00rlkXDl+ w87/thxkQHw2LsGCXtxwPsMP0TPaqWOHEF5qnqqGohcRsLcngcakyQosoUXBIeks 7DiXW0jLIWZRikFWQFDEOSRsh2nLCgKK5KIbv/W/q4IrgDC7oOd6zEg9X3ZDOfRr j3r4VbLmmxrACe1iQ9azAP+hgiyPjv3j5Uh6ghkdyk8XhDdLSNuBCys4CxKZHXCX Alg91A8xEkmPWHpnj1Gu =lFuI -----END PGP SIGNATURE----- --RJWZ9TQ7tP81YmMW--