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

   ## Summary
   
   Two header changes with the same reason: programs expect these names from 
the same headers as with glibc, musl and the BSDs. One commit each.
   
   ### systypes-timeval
   
   glibc, musl and the BSDs make `struct timeval` visible through 
`<sys/types.h>` (glibc and musl through `<sys/select.h>` in their default 
mode), so `<stdlib.h>` also gives it. Programs depend on that: CPython, for 
example, declares functions with `struct timeval *` in its internal header 
`pycore_time.h` without `<sys/time.h>`. On NuttX the type was then declared 
inside the parameter list ("will not be visible outside of this definition"), 
and the function definitions conflicted with the declarations.
   
   This PR moves the definition from `<sys/time.h>` to `<sys/types.h>`, which 
`<sys/time.h>` includes (and `<sys/select.h>` through it). The layout (`time_t 
tv_sec`, `long tv_usec`) does not change.
   
   ### unistd-select
   
   Programs written for other systems use `fd_set`, `FD_SETSIZE`, the 
`FD_xxx()` macros and `select()` without `<sys/select.h>`: glibc and the BSDs 
give them through `<sys/types.h>`, macOS through `<unistd.h>`. The earlier 
standard (SUSv2) also lists only `<sys/time.h>`, `<sys/types.h>` and 
`<unistd.h>` for `select()`, and commit 7b898450356 made `<sys/time.h>` include 
`<sys/select.h>` for this reason. CPython's `selectmodule.c`, for example, 
includes only `<unistd.h>` and `<sys/types.h>`, and does not compile ("unknown 
type name 'fd_set'", implicit `select()`).
   
   This PR includes `<sys/select.h>` in `<unistd.h>`, as macOS does. 
`<sys/types.h>` cannot include it: `<signal.h>` includes `<time.h>`, which 
includes `<sys/types.h>` before `sigset_t` and `struct timespec` are defined, 
and `<sys/select.h>` needs both. Nothing that `<sys/select.h>` includes 
includes `<unistd.h>`, so there is no include cycle.
   
   ## Impact
   
   - systypes-timeval: `struct timeval` is complete after `<sys/types.h>` or 
`<stdlib.h>`, as on other systems. Code that includes `<sys/time.h>` or 
`<sys/select.h>` sees the same type as before. A file that includes 
`<sys/types.h>` and defines its own `struct timeval` does not compile any more; 
there is no such file in nuttx or nuttx-apps (the only definition is in 
`<sys/time.h>`), and the downloaded ESP HAL has none. The definition is inside 
the `__ASSEMBLY__` guard of `<sys/types.h>`, which three `.S` files include. No 
ABI change. The same in flat, protected and kernel builds; nothing per 
architecture. No documentation says where `struct timeval` is defined.
   - unistd-select: After `<unistd.h>`, `fd_set`, `FD_SETSIZE`, 
`FD_ZERO()`/`FD_SET()`/`FD_CLR()`/`FD_ISSET()`, `select()` and `pselect()` are 
visible, and with them the contents of `<signal.h>`, `<time.h>`, `<string.h>` 
and `<sys/time.h>`, which `<sys/select.h>` includes. A file that includes 
`<unistd.h>` and defines its own name that one of these headers also defines 
does not compile any more; there is no such file in nuttx or nuttx-apps (a 
search for the functions and the lower-case macros of these headers). No ABI 
change. The same in flat, protected and kernel builds; nothing per 
architecture. No documentation describes what `<unistd.h>` includes.
   
   ## Testing
   
   The branches were first tested one by one (below). Then all commits of this 
PR together, on master b79dc18e015: systimeval.c, unistdselect.c (CONFIG_PIPES) 
on `qemu-armv8a:knsh` (QEMU with HVF) all PASS, and ostest exits with status 0 
on `qemu-armv8a:knsh` and `qemu-armv8a:nsh`.
   
   ### systypes-timeval
   
   Test program `systimeval.c` (`types`: a function sets and reads the members 
with only `<sys/types.h>` and `<stdlib.h>` included; `same`: `gettimeofday()` 
and `select()`, from headers included later, take the same type), compiled 
against the export of qemu-armv8a:knsh (kernel build) and run under QEMU (HVF):
   
   | | master aeab6fbf989 | this PR |
   |---|---|---|
   | `systimeval` | does not compile (invalid use of undefined type 'struct 
timeval') | types PASS, same PASS |
   
   ostest exits with status 0 on qemu-armv8a:knsh (kernel) and qemu-armv8a:nsh 
(flat).
   
   Header check: each public header of the knsh export (148 headers in 
`include/`, `sys/`, `netinet/`, `arpa/`, `net/`) compiled alone, after 
`<unistd.h>`, before `<unistd.h>` and after `<sys/types.h>`: the same result as 
on master (all compile, except `sys/syscall_lookup.h`, which is not a 
standalone header).
   
   Builds, each without new warnings: stm32f4discovery:nsh (flat, Cortex-M4), 
lm3s6965-ek:qemu-protected (protected, Cortex-M3), rv-virt:knsh64 (kernel, 
RISC-V; its `.S` files include `<sys/types.h>`), rv-virt:citest64 (flat, 
RISC-V, with the cmocka and libc test apps) and sim:nsh (macOS host, whose own 
`struct timeval` is in the host headers).
   
   ### unistd-select
   
   Test program `unistdselect.c` (`types`: `fd_set`, `FD_SETSIZE`, `FD_ZERO()`, 
`FD_SET()`, `FD_ISSET()` with only `<unistd.h>` included; `pipe`: `select()` on 
a pipe is not readable, then readable after a `write()`), compiled against the 
export of qemu-armv8a:knsh (kernel build, with `CONFIG_PIPES`) and run under 
QEMU (HVF):
   
   | | master aeab6fbf989 | this PR |
   |---|---|---|
   | `unistdselect` | does not compile (unknown type name 'fd_set', implicit 
`select()`) | types PASS, pipe PASS |
   
   ostest exits with status 0 on qemu-armv8a:knsh (kernel) and qemu-armv8a:nsh 
(flat).
   
   Header check: each public header of the knsh export (`include/*.h`, `sys/`, 
`netinet/`, `arpa/`, `net/`; 148 headers) compiled alone, after `<unistd.h>`, 
before `<unistd.h>` and after `<sys/types.h>`: the same result as on master 
(all compile, except `sys/syscall_lookup.h`, which is not a standalone header). 
`gcc -H` shows `<unistd.h>` once.
   
   Builds, each without new warnings: stm32f4discovery:nsh (flat, Cortex-M4), 
lm3s6965-ek:qemu-protected (protected, Cortex-M3), rv-virt:knsh64 (kernel, 
RISC-V), rv-virt:citest64 (flat, RISC-V, with the cmocka and libc test apps) 
and sim:nsh (macOS host).
   
   `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