Skip to content

apps: Include the headers that are used. - #3839

Merged
xiaoxiang781216 merged 2 commits into
apache:masterfrom
casaroli:apps-include-headers
Oct 14, 2026
Merged

xiaoxiang781216 merged 2 commits into
apache:masterfrom
casaroli:apps-include-headers

Conversation

@casaroli

@casaroli casaroli commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Some apps files use declarations from stdlib.h, unistd.h, pthread.h and other headers without including them. They got the declarations only because NuttX's stdio.h included nuttx/lib/lib.h, and through it stdlib.h, nuttx/sched.h and more. apache/nuttx#20565 stops this.

  • stdlib.h: adjtime, ads7046, audio_rttl, baromonitor, bmp280, hx711, netpkt_ethercat, nimble_blecent (main, peer), nimble_bleprph (main, gatt_svr), shv-test, stepper, tmp112, dhcpd, netlib_iptables, netlib_ip6tables, adcscope, iptables, ip6tables, nxdiag, sensorscope, nxboot boot.c, nand_sim, pcitest, cachetest, ymodem rb_main.c and sb_main.c.
  • unistd.h: nxboot boot.c and flash.c, fbcon, netpkt_ethercat, nimble_blecent, nimble_bleprph, shv-test, stepper, watched, lapi_other, ofloader, nand_sim, ser, setest, drivertest_block, drivertest_i2c_spi, drivertest_relay, epoll, fdsantest_simple, memfd_test, i8sak_acceptassoc, passwd_delete, plcatool. NXDoom: in i_timer.h, which every NXDoom file that calls usleep() includes.
  • pthread.h: camera_bkgd, mqttc_pub, nxterm, pty_test, pwfb_events, pwlines_events, ofloader, epoll, memfd_test, ostest sched_thread_local.c, i8sak.h.
  • sched.h: ble_main, calib_udelay, drivertest_pm_smp. nuttx/atomic.h: the atomic test. nuttx/kmalloc.h: nand_sim, drivertest_block.
  • testing/cmocka: the downloaded cmocka.c uses ftruncate(). cmocka_platform.h, which cmocka.c includes, now includes unistd.h.
  • system/zlib: the downloaded gzlib.c, gzread.c and gzwrite.c use lseek(), read() and write(). After the download, the Make and CMake builds now make zconf.h include unistd.h, as zlib's configure does on Unix (#ifdef HAVE_UNISTD_H becomes #if 1), so zlib and the programs that include zlib.h agree on z_off_t.

The first commit fixes the old nxstyle and codespell errors in the changed files, because CI checks each changed file as a whole. Only the layout changes, plus four spelling fixes and one .codespell-ignore-lines entry (the path testing/drivers/ser/ser.c).

Impact

None on master. Needed by apache/nuttx#20565.

Testing

To find every file, each of the 1753 apps C files was compiled with -fsyntax-only -Werror=implicit-function-declaration, once against nuttx master and once against apache/nuttx#20565, for qemu-armv8a:nsh, qemu-armv8a:knsh, sim:citest and sim:ostest. The errors that only #20565 gives are all fixed. Files that include headers of downloaded packages (lvgl, nimble, cmocka and others) were checked again with empty stand-ins for the missing headers and the real include directories of the apps tree. What remains is config dependent (for example apb_alloc() without CONFIG_AUDIO), and in a kernel build, programs that call kernel functions (register_driver(), open_blockdriver(), task_create()), which cannot run there anyway.

Not changed: examples/sensor_fusion/sensor_fusion_main.c (EXIT_SUCCESS) and crypto/openssl_mbedtls_wrapper/mbedtls/bio_lib.c (free()) need stdlib.h too, but nxstyle rejects their mixed-case library names (Fusion, OpenSSL), so CI would fail on any change to them. No configuration in the tree builds them. examples/nanoxterm is not changed either: its errors show only with the stand-ins for the Nano-X headers, which were not available for the check.

Earlier checks, with apache/nuttx#20565, Make, -Werror, on macOS: esp32c6-devkitc:oa_tc6, stm32f746g-disco:dropbear and linum-stm32h753bi:zbus failed before and build after. qemu-armv7a:full (with make -k) compiles the zlib and ymodem files without errors; its remaining errors are in libcxx and mbedtls, as on master. qemu-armv8a:nsh with CONFIG_LIB_ZLIB builds with Make and with CMake.

tools/checkpatch.sh -c -u -m -g passes.

Comment thread system/zlib/Makefile Outdated
The next commit adds includes to these files, and checkpatch checks each
changed file as a whole.  So fix their old nxstyle errors first: the
indentation of case labels and other lines, blank lines after
declarations, a long comment, and a long string (split in two, with the
same output).  Only the layout changes.

codespell also checks the whole files: fix "Types" and "transfer" in
sb_main.c, "corresponds" in hx711_main.c and "primitive" in
i8sak_acceptassoc.c, and add the path line of testing/drivers/ser/ser.c
to .codespell-ignore-lines ("ser" is not a typo there).

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli
casaroli force-pushed the apps-include-headers branch from c6ea72b to 6910dc5 Compare October 13, 2026 05:25
@github-actions github-actions Bot added Size: L and removed Size: M labels Oct 13, 2026
These files use declarations from stdlib.h, unistd.h, pthread.h and
other headers without including them.  They got the declarations only
because stdio.h included nuttx/lib/lib.h, and through it stdlib.h,
nuttx/sched.h and more.

- stdlib.h: adjtime, ads7046, audio_rttl, baromonitor, bmp280, hx711,
  netpkt_ethercat, nimble_blecent (main, peer), nimble_bleprph (main,
  gatt_svr), shv-test, stepper, tmp112, dhcpd, netlib_iptables,
  netlib_ip6tables, adcscope, iptables, ip6tables, nxdiag, sensorscope,
  nxboot boot.c, nand_sim, pcitest, cachetest, ymodem rb and sb.
- unistd.h: nxboot boot.c and flash.c, fbcon, netpkt_ethercat,
  nimble_blecent, nimble_bleprph, shv-test, stepper, watched,
  lapi_other, ofloader, nand_sim, ser, setest, drivertest_block,
  drivertest_i2c_spi, drivertest_relay, epoll, fdsantest_simple,
  memfd_test, i8sak_acceptassoc, passwd_delete, plcatool.  NXDoom: in
  i_timer.h, which every file that calls usleep() includes.
- pthread.h: camera_bkgd, mqttc_pub, nxterm, pty_test, pwfb_events,
  pwlines_events, ofloader, epoll, memfd_test, ostest
  sched_thread_local.c and i8sak.h.
- sched.h: ble_main, calib_udelay, drivertest_pm_smp.
  nuttx/atomic.h: the atomic test.  nuttx/kmalloc.h: nand_sim,
  drivertest_block.
- testing/cmocka: the downloaded cmocka.c uses ftruncate(); include
  unistd.h in cmocka_platform.h, which cmocka.c includes.
- system/zlib: the downloaded gzlib.c, gzread.c and gzwrite.c use
  lseek(), read() and write(); make zconf.h include unistd.h, as
  zlib's configure does on Unix.
- interpreters/wamr: the NuttX platform of older WAMR versions (sim:wamr
  pins one) uses the pthread types without including pthread.h; build
  WAMR with -include pthread.h.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli
casaroli force-pushed the apps-include-headers branch from 6910dc5 to 20fb2df Compare October 13, 2026 06:34

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @casaroli :-)

@xiaoxiang781216
xiaoxiang781216 merged commit c56e793 into apache:master Oct 14, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants