Skip to content

gh-155321: Avoid Python.h POSIX macro redefinition - #155343

Open
RealBhupesh wants to merge 2 commits into
python:mainfrom
RealBhupesh:agent/gh-155321-python-stdlib-include
Open

gh-155321: Avoid Python.h POSIX macro redefinition#155343
RealBhupesh wants to merge 2 commits into
python:mainfrom
RealBhupesh:agent/gh-155321-python-stdlib-include

Conversation

@RealBhupesh

@RealBhupesh RealBhupesh commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #155321.

Summary:

  • Generate a private configure marker and define _POSIX_C_SOURCE only when it was not defined by an earlier system-header include.
  • Keep the configured 202405L value when Python.h is included first.

Tests:

  • clang -Werror include-order checks with _POSIX_C_SOURCE present and absent.
  • ./configure --with-pydebug --without-lto
  • make -j4
  • ./python.exe -m test test_zstd (119 tests)

@python-cla-bot

python-cla-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@RealBhupesh
RealBhupesh marked this pull request as ready for review August 7, 2026 14:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 69983c8e10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread configure.ac
Comment on lines +942 to +943
AC_DEFINE([_PYTHON_POSIX_C_SOURCE], [1],
[Define to configure _POSIX_C_SOURCE in pyconfig.h])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the POSIX macro during configure probes

When configuring on a target where _XOPEN_SOURCE alone does not expose the required POSIX declarations—specifically Tru64 and some HP-UX cases called out immediately above—this replacement leaves only _PYTHON_POSIX_C_SOURCE in confdefs.h; the conditional that turns it into _POSIX_C_SOURCE exists only in the generated pyconfig.h. Consequently, all subsequent configure header/function probes run without the required feature-test macro and can record false-negative HAVE_* results, even though the actual Python build later sees _POSIX_C_SOURCE=202405L. Preserve the real macro for configure test compilations while using the marker only for generating the guarded public-header definition.

Useful? React with 👍 / 👎.

@@ -0,0 +1,2 @@
Allow :file:`Python.h` to be included after system headers that define
``_POSIX_C_SOURCE`` without causing a macro redefinition diagnostic.

@aisk aisk Aug 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the filename should follow the naming convention of other news entries. In particular, the timestamp should be the actual time rather than a zero timestamp, and the final part should be a random string

Blurb and blurb-it are the recommended tools for generating news entries. See: https://devguide.python.org/getting-started/pull-request-lifecycle/#how-to-add-a-news-entry

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.

Python.h conflicts with stdlib.h if included after that

2 participants