Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ AH_BOTTOM([
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
#endif

/* Define _POSIX_C_SOURCE only when it was not defined by an earlier
system-header include. */
#ifdef _PYTHON_POSIX_C_SOURCE
# ifndef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 202405L
# endif
# undef _PYTHON_POSIX_C_SOURCE
#endif

#endif /*Py_PYCONFIG_H*/
])

Expand Down Expand Up @@ -930,8 +939,8 @@ then
AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1],
[Define to activate Unix95-and-earlier features])

AC_DEFINE([_POSIX_C_SOURCE], [202405L],
[Define to activate features from IEEE Std 1003.1-2024])
AC_DEFINE([_PYTHON_POSIX_C_SOURCE], [1],
[Define to configure _POSIX_C_SOURCE in pyconfig.h])
Comment on lines +942 to +943

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 👍 / 👎.


# Defining _POSIX_C_SOURCE and _XOPEN_SOURCE hides C23 library
# declarations on FreeBSD (e.g. sinpi() in math.h) when compiling
Expand Down
15 changes: 12 additions & 3 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2161,15 +2161,15 @@
/* Define on NetBSD to activate all library features */
#undef _NETBSD_SOURCE

/* Define to activate features from IEEE Std 1003.1-2024 */
#undef _POSIX_C_SOURCE

/* Define if you have POSIX threads, and your system does not define that. */
#undef _POSIX_THREADS

/* framework name */
#undef _PYTHONFRAMEWORK

/* Define to configure _POSIX_C_SOURCE in pyconfig.h */
#undef _PYTHON_POSIX_C_SOURCE

/* Maximum length in bytes of a thread name */
#undef _PYTHREAD_NAME_MAXLEN

Expand Down Expand Up @@ -2263,5 +2263,14 @@
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
#endif

/* Define _POSIX_C_SOURCE only when it was not defined by an earlier
system-header include. */
#ifdef _PYTHON_POSIX_C_SOURCE
# ifndef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 202405L
# endif
# undef _PYTHON_POSIX_C_SOURCE
#endif

#endif /*Py_PYCONFIG_H*/

Loading