Skip to content

fix(build): undef POSIX feature macros before including Python.h - #228

Open
Neira12 wants to merge 1 commit into
Autonomy-Logic:developmentfrom
Neira12:fix/python-header-order
Open

Neira12 wants to merge 1 commit into
Autonomy-Logic:developmentfrom
Neira12:fix/python-header-order

Conversation

@Neira12

@Neira12 Neira12 commented Oct 23, 2026

Copy link
Copy Markdown

Summary

Fixes #152: the runtime core fails to build with "_POSIX_C_SOURCE" redefined / "_XOPEN_SOURCE" redefined errors from pyconfig.h.

Two things combine:

  • glibc's POSIX.1-2024 update (glibc commit a5cc3018f3, "Add feature test macros for POSIX.1-2024") makes features.h set _POSIX_C_SOURCE 202405L and, with _GNU_SOURCE, _XOPEN_SOURCE 800. pyconfig.h defines them unconditionally as 200809L and 700 (Python 3.10 and 3.13 alike), so any file that includes a libc header before Python.h redefines them with a different value.
  • GCC hides warnings inside system headers, so this only shows when the Python headers are not under a system include path (pyenv, conda, a self-built Python) — which matches the reporter's setup. With -Werror the warning stops the build.

python_plugin_bridge.h reaches Python.h after libc headers in plc_boot.c, plc_retain.cpp, plc_state_manager.cpp and unix_socket.c. The fix #undefs the two macros right before #include <Python.h> there. libc has already consumed them in features.h (include-guarded), so nothing it declares changes. The existing #pragma GCC diagnostic ignored "-Wcpp" does not cover macro redefinition in GCC; it is left as is. plugin_driver.c and plc_main.c include Python.h first and are not affected.

Ticket

External contribution, no RTOP ticket. Closes #152.

How it was tested

  • Reproduced on Ubuntu 24.04 (GCC 13.3, glibc 2.39) by putting the Python 3.13 headers outside /usr/include (via a python3-embed.pc on PKG_CONFIG_PATH) and shadowing features.h with the POSIX.1-2024 values (202405L / 800). Before the change, make fails in plc_boot.c, plc_retain.cpp, plc_state_manager.cpp and unix_socket.c with the errors from the issue; after it, plc_main builds.
  • Normal build (system Python headers, real glibc 2.39) still builds, and the preprocessed output of those four files is byte-identical before and after the change.
  • tests/host/run.sh: all passed.
  • clang-format --style=file reports no changes for the edited header.
  • Not tested with a real glibc that ships the new values or with Python 3.10 itself; Python 3.10.22's configure.ac defines the same 200809L / 700.

Checklist

  • bash scripts/run-pytest.sh passes: not run; the change is a C header include-order fix with no Python-side effect.
  • pre-commit run clean: clang-format clean for the edited .h.
  • Docs updated if behavior changed (README, CLAUDE.md, docs/): no documented behaviour changes.
  • Follows the shared review process (summary in .claude/review-guidelines.md): no IPC, scan-cycle or plugin ABI change.

Contributor License Agreement

🤖 Generated with Claude Code

https://claude.ai/code/session_015ZahKj3kRaL9bQVSUQSHjK

pyconfig.h defines _POSIX_C_SOURCE 200809L and _XOPEN_SOURCE 700 unconditionally. A glibc with the POSIX.1-2024 feature macros sets 202405L / 800 first, so a file that includes libc headers before Python.h fails under -Werror when the Python headers are not on a system include path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ZahKj3kRaL9bQVSUQSHjK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant