From owner-freebsd-arch@FreeBSD.ORG Thu Sep 4 04:17:47 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5FE51A51 for ; Thu, 4 Sep 2014 04:17:47 +0000 (UTC) Received: from mail-ig0-f180.google.com (mail-ig0-f180.google.com [209.85.213.180]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 22ABD178A for ; Thu, 4 Sep 2014 04:17:46 +0000 (UTC) Received: by mail-ig0-f180.google.com with SMTP id hn18so435115igb.13 for ; Wed, 03 Sep 2014 21:17:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:content-type:mime-version:subject:from :in-reply-to:date:cc:message-id:references:to; bh=rLVqAjQfa9hYhlmXEBsGizx8Hwj3uwKSSLj1MfP4r0w=; b=bpQILFTPUAhpRfNtrlu3xiPjeZUGQDrpW7qI4hGhsue9JW3GKTKm0lA+IVwiRUAEIu iv4LpodaipWIWDXbc8l+YE25bVk+s/B8YVJl0nuqTLyDjLSumx7+dW0Aur4bxs8UzSlI WdU2/dJ6iaNjMcFYbgwq4sDBSa9SPbRdA/AOgStJhP8reEYlxvCQEnQHZz0oMpuZTtmo YTZ3lH3i9SvjSMozeCObzkoq+9jnYBlRD03D2VKOoqMno3ZgJnI6VRsdXtNYPy3u9W9m 9IWZ90y51k5h+QOFcV81SWp3tc3s65fAN7tiACZt439SMF628soQrf2lDKeYZ5HKlRyH LBhw== X-Gm-Message-State: ALoCoQmj1WY9wqVAmB0fr+5HEeW2YeaeQdCnJJ+k9gkeFQbTmagf8TZl3UQV9EBO1exSSfJvfcxu X-Received: by 10.42.35.8 with SMTP id o8mr1804870icd.41.1409804259980; Wed, 03 Sep 2014 21:17:39 -0700 (PDT) Received: from bsdimp.bsdimp.com (50-78-194-198-static.hfc.comcastbusiness.net. [50.78.194.198]) by mx.google.com with ESMTPSA id cz10sm7409559igc.5.2014.09.03.21.17.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 21:17:39 -0700 (PDT) Sender: Warner Losh Content-Type: multipart/signed; boundary="Apple-Mail=_E656BEA7-B9C4-4EB2-A646-7AC292F62DF9"; protocol="application/pgp-signature"; micalg=pgp-sha512 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: [RFC] Add __arraycount from NetBSD to sys/cdefs.h From: Warner Losh In-Reply-To: Date: Wed, 3 Sep 2014 22:17:37 -0600 Message-Id: <8D279BDC-7D40-4750-8DA7-A4535DD2E458@bsdimp.com> References: To: Garrett Cooper X-Mailer: Apple Mail (2.1878.6) Cc: Julio Merino , "rpaulo@freebsd.org" , freebsd-arch@freebsd.org 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: Thu, 04 Sep 2014 04:17:47 -0000 --Apple-Mail=_E656BEA7-B9C4-4EB2-A646-7AC292F62DF9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On Sep 3, 2014, at 9:45 PM, Garrett Cooper = wrote: > 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 = included" > $ gcc -D_KERNEL -c cdefs_pound_define.c > cdefs_pound_define.c:4:2: warning: #warning "sys/cdefs.h has been = included=94 I wouldn=92t bother changing the nitems #define. There=92s no need, = really, to do that. I=92d also be more inclined to believe the test if you tested what the = thing does rather than test for an artificial, implementation defined = side effect. But honestly the amount of duplication saved here is rather tiny=85 Warner --Apple-Mail=_E656BEA7-B9C4-4EB2-A646-7AC292F62DF9 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJUB+fhAAoJEGwc0Sh9sBEAjp4QAI7/yB+LvUkAmVM/O1DoX4wp /vbOT1awGQCWCsQGpT8r7PMIskfzwHve+JQxEfPoa8ddHVeaDuDTBw0P4YjLTDqW 828TdMCcQQ6/QpFxZooOxhAsnAwJErko+HmPy0q+JMUPlqresg8m5kADA0X9wU+4 NT1TxFjE5wdET7NyWqic0A2nP6Z7WewSbTfZmXqkz9N0abGl4Lu4uGB8lrfJwR/m NMco9Q5odpNXXjdi+RiGmM+I4HSQUkEu1s9mG0KSNIPdH+fdPlLDdSIkH+0RALB+ wi3s/xvyMZXYISXsH1IT+4qe+BtPX2PZI+HrsQIJOXlAhWj+yDbzko0Xl84yS7A/ pnx6uD46aK8w1JsjjCPNpj0cQ9e1K4bBaj7dHbkuInMszseAeKEnJcjMNLlZ6Flu 0DjNvLEDg0CRX56Bxm5vYuACdf7m8ly6zwOdEY1bHr2NQmFEEC5432BfX0z2dwNk 2rkA0Bjfq7y+dK3DUqVn/8qeZS03Pf57V30tWxNc5Prm/9FHme7LqHH7K68ROm3u LVqGMUR69iLTL6UB2+9MGdSmAcVijdsgL2UjB6LUtRffRlbsCrs5vx9sijCQkqEx 4O5tmBYI5gXlPD0809COnM1RpIODJersiLsGZtrNT91RhxFsSafJPviMsrbkWMe8 T8LtfmW+iq3rPeXwDkNr =wgEK -----END PGP SIGNATURE----- --Apple-Mail=_E656BEA7-B9C4-4EB2-A646-7AC292F62DF9--