Fix support for NetBSD and enable native code on NetBSD/aarch64#11097
Fix support for NetBSD and enable native code on NetBSD/aarch64#11097Octachron merged 3 commits intoocaml:trunkfrom
Conversation
4b250c9 to
6ade4fb
Compare
runtime/sak.c
Outdated
| #define strncmp_os strncmp | ||
| #ifdef __NetBSD__ | ||
| /* NOTE: See CAVEATS section in https://man.netbsd.org/ctype.3 */ | ||
| #define toupper_os(x) toupper((unsigned int)x) |
There was a problem hiding this comment.
Given this from that manpage:
Some implementations of libc, such as glibc as of 2018, attempt to avoid
the worst of the undefined behavior by defining the functions to work for
all integer inputs representable by either unsigned char or char, and
suppress the warning. However, this is not an excuse for avoiding con-
version to unsigned char: if EOF coincides with any such value, as it
does when it is -1 on platforms with signed char, programs that pass char
will still necessarily confuse the classification and mapping of EOF with
the classification and mapping of some non-EOF inputs.
Should we just unconditionally cast to (unsigned int) on all platforms, including glibc?
There was a problem hiding this comment.
oooops, I meant to use unsigned char not unsigned int. Fixed.
There was a problem hiding this comment.
Thanks; looking at the glibc man page for toupper, it looks appropriate to always cast toupper_os()'s argument to unsigned char:
The standards require that the argument c for these functions is
either EOF or a value that is representable in the type unsigned
char. If the argument c is of type char, it must be cast to
unsigned char, as in the following example:
char c;
...
res = toupper((unsigned char) c);
This is necessary because char may be the equivalent signed char,
in which case a byte where the top bit is set would be sign
extended when converting to int, yielding a value that is outside
the range of unsigned char.
6ade4fb to
d9875a7
Compare
avsm
left a comment
There was a problem hiding this comment.
The NetBSD fixes look good to me. If I could get another approval on the toupper cast before merging, that'd be nice...
| #define toupper_os toupper | ||
| /* NOTE: See CAVEATS section in https://man.netbsd.org/ctype.3 */ | ||
| /* and NOTE section in https://man7.org/linux/man-pages/man3/toupper.3.html */ | ||
| #define toupper_os(x) toupper((unsigned char)x) |
There was a problem hiding this comment.
Am I reading correctly that this change is mainly to avoid a compiler warning on NetBSD?
There was a problem hiding this comment.
Yes. It is triggered by -Werror=char-subscripts
There was a problem hiding this comment.
Then the toupper_os change seems fine to me (and this is the only change that will survive rebasing).
|
This looks fine to me, I will approve and merge once rebased. |
75623c9 to
72a4f98
Compare
|
You may want to edit the commit message of the last commit. |
72a4f98 to
6ffb182
Compare
6ffb182 to
f54b3ac
Compare
|
The PR should have been cherry-picked to 5.0 indeed. So it is fine to cherry-pick it along with #11639 . |
Fix support for NetBSD and enable native code on NetBSD/aarch64 (cherry picked from commit ef07bd8)
|
Done: f35d5d6 |
Support for it was added in ocaml#11097
Support for it was added in #11097
Support for it was added in ocaml#11097
Same as #11092 and #11096 but with some fixes to make it actually build.
Was failing with:
and
All the manual pages necessary to understand those fixes have been added as comments in the code where they are needed.