Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Mar 2023 02:13:29 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Colin Percival <cperciva@tarsnap.com>
Cc:        Warner Losh <imp@freebsd.org>, src-committers <src-committers@freebsd.org>,  "<dev-commits-src-all@freebsd.org>" <dev-commits-src-all@freebsd.org>, dev-commits-src-main@freebsd.org
Subject:   Re: git: ed52baf51bd1 - main - _endian.h: Include sys/ctypes.h for visibility macros
Message-ID:  <CANCZdfqJe4sC_Ghd48iQbRyQBQwxKE6r5=%2Bk2iwg2OsYMDHRbg@mail.gmail.com>
In-Reply-To: <010001870d7559c1-09ae94d7-ae1d-4a75-880e-e4f55b4b178e-000000@email.amazonses.com>
References:  <202303220226.32M2QLoe029463@gitrepo.freebsd.org> <010001870d7559c1-09ae94d7-ae1d-4a75-880e-e4f55b4b178e-000000@email.amazonses.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--000000000000b6c50e05f78cda61
Content-Type: text/plain; charset="UTF-8"

On Thu, Mar 23, 2023, 8:53 AM Colin Percival <cperciva@tarsnap.com> wrote:

>
>
> On 3/21/23 19:26, Warner Losh wrote:
> >      [...]
> >      This had the side effect of sometimes (in the traditional BSD
> >      compliation environment)
> >       #if BYTE_ORDER == LITTLE_ENDIAN
> >      and
> >       #if BYTE_ORDER == BIG_ENDIAN
> >      both being true because none of these were defined. This fixes
> >      that. It also fixes including it after <stdio.h> but not before.
>
> Would it be worth adding
>
> #if LITTLE_ENDIAN == BIG_ENDIAN
> #error Endian defines are broken!
> #endif
>
> just to ensure that any future issues show up quickly?
>


Not in *endian.h. The problem is that we fail to define them
at all, then user programs expect to use them and sometimes
they are defined, and other times they are not. Inside of endian.h
the above can be true when we're not compiling for __BSD_VISIBLE
because in C's reprocessor, undefined values are substituted with
zero always...

I'd planned on adding a test for it, though, to make sure that we catch
this case in testing. But I was planning on that test being:

#include <endian.h>
int big_endian = BIG_ENDIAN;
int little_endian = LITTLE_ENDIAN;
int byte_order = BYTE_ORDER

which will catch the undefined case since there's no 'substitute 0
for undefined' in an rval.

Warner

--000000000000b6c50e05f78cda61
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"auto"><div><br><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Thu, Mar 23, 2023, 8:53 AM Colin P=
ercival &lt;<a href=3D"mailto:cperciva@tarsnap.com" target=3D"_blank">cperc=
iva@tarsnap.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 3/21/23 19:26, Warner Losh wrote:<br>
&gt;=C2=A0 =C2=A0 =C2=A0 [...]<br>
&gt;=C2=A0 =C2=A0 =C2=A0 This had the side effect of sometimes (in the trad=
itional BSD<br>
&gt;=C2=A0 =C2=A0 =C2=A0 compliation environment)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0#if BYTE_ORDER =3D=3D LITTLE_ENDIAN<br>
&gt;=C2=A0 =C2=A0 =C2=A0 and<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0#if BYTE_ORDER =3D=3D BIG_ENDIAN<br>
&gt;=C2=A0 =C2=A0 =C2=A0 both being true because none of these were defined=
. This fixes<br>
&gt;=C2=A0 =C2=A0 =C2=A0 that. It also fixes including it after &lt;stdio.h=
&gt; but not before.<br>
<br>
Would it be worth adding<br>
<br>
#if LITTLE_ENDIAN =3D=3D BIG_ENDIAN<br>
#error Endian defines are broken!<br>
#endif<br>
<br>
just to ensure that any future issues show up quickly?<br></blockquote></di=
v></div><div dir=3D"auto"><br></div><div dir=3D"auto"><br></div><div dir=3D=
"auto">Not in *endian.h. The problem is that we fail to define them</div><d=
iv>at all, then user programs expect to use them and sometimes</div><div>th=
ey are defined, and other times they are not. Inside of endian.h</div><div>=
the above can be true when we&#39;re not compiling for __BSD_VISIBLE</div><=
div>because in C&#39;s reprocessor, undefined values are substituted with</=
div><div>zero always...</div><div><br></div><div>I&#39;d planned on adding =
a test for it, though, to make sure that we catch<br></div><div>this case i=
n testing. But I was planning on that test being:</div><div><br></div><div>=
#include &lt;endian.h&gt;</div><div>int big_endian =3D BIG_ENDIAN;</div><di=
v>int little_endian =3D LITTLE_ENDIAN;</div><div>int byte_order =3D BYTE_OR=
DER</div><div><br></div><div>which will catch the undefined case since ther=
e&#39;s no &#39;substitute 0</div><div>for undefined&#39; in an rval.</div>=
<div><br></div><div>Warner</div></div>
</div>

--000000000000b6c50e05f78cda61--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfqJe4sC_Ghd48iQbRyQBQwxKE6r5=%2Bk2iwg2OsYMDHRbg>