casaroli opened a new pull request, #21569:
URL: https://github.com/apache/nuttx/pull/21569

   ## Summary
   
   glibc and the BSDs define `BYTE_ORDER`, `LITTLE_ENDIAN` and `BIG_ENDIAN` in 
`<sys/param.h>`, and programs test them after they include only that header 
(for example autoconf's `AC_C_BIGENDIAN`). NuttX defines them only in 
`<sys/endian.h>`. An undefined name is 0 in `#if`, so `#if BYTE_ORDER == 
BIG_ENDIAN` is true on every target, and such a program takes its big-endian 
path on a little-endian CPU.
   
   This PR defines the three macros in `<sys/param.h>` with the same values as 
`<sys/endian.h>`, so a program can include both headers in any order. Only 
these three names are added: the conversion and byte swap macros stay in 
`<sys/endian.h>`.
   
   `<sys/param.h>` does not include `<sys/endian.h>`, because `<sys/endian.h>` 
also defines the OpenBSD names `swap16`, `swap32`, `swap64`, `betoh16`, 
`letoh16`, `bemtoh16`, `htobem16` and the others up to `htolem64`. 628 files in 
nuttx and 133 in nuttx-apps include `<sys/param.h>`, so a program with its own 
`swap16()` (as `drivers/sensors/mpu9250_uorb.c` has) would not compile.
   
   ## Impact
   
   `<sys/param.h>` gives three more names, with the same definitions as 
`<sys/endian.h>` (an identical redefinition, so no warning when both are 
included). No other header changes. The in-tree users of these names compare 
`BYTE_ORDER` with the two names and do not change. No Documentation change.
   
   ## Testing
   
   Test programs: `paramorder.c` (`<sys/param.h>` only: the three names are 
defined, `BYTE_ORDER` is the order of a stored word, and `#if BYTE_ORDER == 
BIG_ENDIAN` agrees with it), `paramboth.c` (the same, with `<endian.h>` after 
`<sys/param.h>`), `paramrev.c` (`<endian.h>` before `<sys/param.h>`).
   
   - qemu-armv8a:knsh (kernel build, arm64, QEMU): on master paramorder fails 3 
of 3 (the big-endian branch is taken); with this PR paramorder 3/3, paramboth 
3/3 and paramrev PASS. ostest exits 0 on qemu-armv8a:knsh and qemu-armv8a:nsh. 
No "redefined" warning in the builds.
   - Build only, with `EXTRAFLAGS="-Wno-cpp -Werror"`: nucleo-f072rb:nsh 
(Cortex-M0), qemu-armv8a:nsh (arm64), rv-virt:pnsh64 (protected, RISC-V), 
esp32s3-devkit:nsh (Xtensa): all build with no compiler warning.
   - SDCC 4.6.0 for z80 (z80sim:nsh headers): a file that includes 
`<endian.h>`, `<sys/param.h>` and `<limits.h>` and checks `BYTE_ORDER` in `#if` 
compiles.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to