casaroli opened a new pull request, #20565: URL: https://github.com/apache/nuttx/pull/20565
## Summary `stdio.h` includes `nuttx/fs/fs.h` and `nuttx/lib/lib.h`. So every program that includes `stdio.h` also sees the kernel's `struct file`, `struct inode` and the other file system types. A program that defines its own `struct file` does not compile: `error: redefinition of 'struct file'`. In the user space of a kernel build (`CONFIG_BUILD_KERNEL` and not `__KERNEL__`), programs cannot use those types. This PR makes `stdio.h` stop including the two headers there. Kernel code, and flat and protected builds, still get them. Removing them for every build breaks many files that rely on the indirect includes. `stdio.h` itself needs only the `FILE` name, the `fopencookie()` callback types and `lib_get_stream()` (which `stdin`, `stdout` and `stderr` expand to). `FILE` stays an incomplete type, `stdio.h` declares `lib_get_stream()`, and the cookie types move from `fs.h` to a new `nuttx/fs/cookie.h` that both `stdio.h` and `fs.h` include. The libc files that are built for user space and used kernel types or other headers through `stdio.h` now include what they use. The first commit fixes the old nxstyle errors in three of the touched files, with no code change: the object code of the three files is identical before and after (`qemu-armv8a:nsh` with `CONFIG_LIBC_LOCALE`). ## Impact Programs of a kernel build that used kernel file system types or `nuttx/lib/lib.h` macros through `stdio.h` must include those headers themselves. Flat and protected builds, and kernel code, do not change. Lint: `lib_iconv.c` keeps 8 nxstyle warnings (`#include outside of 'Included Files' section`). They are on the `#include` lines of the code page tables inside array initializers, they are on master already, and they cannot be fixed without moving the tables. The first commit fixes all other nxstyle errors in the file. ## Testing A program that defines its own `struct file` and includes `<stdio.h>`, built outside the tree against the `qemu-armv8a:knsh` export package and run in QEMU 11: Before: ``` ownfile.c:5:8: error: redefinition of 'struct file' ``` After: ``` nsh> ownfile ownfile: struct file value 42 ``` Kernel builds with `-Wno-cpp -Werror`, each followed by `make export` and the apps `make import` (all apps of the configuration compiled for user space): `qemu-armv8a:knsh`, `imx93-evk:knsh`, `qemu-armv7a:knsh`, `sabre-6quad:netknsh`, `sama5d4-ek:knsh`, `rv-virt:knsh`, `rv-virt:knsh64`, `rv-virt:ksmp64`, `rv-virt:knsh_paging`, `rv-virt:knetnsh64`, `rv-virt:kfb64`, `icicle:knsh`, `canmv230:knsh`, `esp32s3-devkit:kernel_n8r2`. The apps import needs apache/nuttx-apps#3820 and apache/nuttx-apps#3823, which add includes that some apps files took from `stdio.h` indirectly. Flat builds with `-Wno-cpp -Werror`, size unchanged: `lm3s6965-ek:qemu-flat`, `mps2-an500:nsh`. `tools/checkpatch.sh -c -u -m -g` passes except the 8 `lib_iconv.c` warnings above. depends-on: apache/nuttx-apps/pull/3820 depends-on: apache/nuttx-apps/pull/3823 -- 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]
