Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Sep 2014 22:17:37 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Garrett Cooper <yaneurabeya@gmail.com>
Cc:        Julio Merino <jmmv@freebsd.org>, "rpaulo@freebsd.org" <rpaulo@freebsd.org>, freebsd-arch@freebsd.org
Subject:   Re: [RFC] Add __arraycount from NetBSD to sys/cdefs.h
Message-ID:  <8D279BDC-7D40-4750-8DA7-A4535DD2E458@bsdimp.com>
In-Reply-To: <CAGHfRMBMPra5YXDn0e83dpVxwnarg3DL8o31xr7DhWv%2BVXskTg@mail.gmail.com>
References:  <CAGHfRMBMPra5YXDn0e83dpVxwnarg3DL8o31xr7DhWv%2BVXskTg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--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 <yaneurabeya@gmail.com> =
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 <sys/param.h>
>=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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8D279BDC-7D40-4750-8DA7-A4535DD2E458>