From f9b8d1559122a8384167abf89074b2c4f6e4e624 Mon Sep 17 00:00:00 2001 From: RealBhupesh Date: Fri, 7 Aug 2026 19:31:17 +0530 Subject: [PATCH 1/2] gh-155321: Avoid Python.h POSIX macro redefinition --- ...8-07-00-00-00.gh-issue-155321.pythonh-posix.rst | 2 ++ configure | 2 +- configure.ac | 13 +++++++++++-- pyconfig.h.in | 14 +++++++++++--- 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2026-08-07-00-00-00.gh-issue-155321.pythonh-posix.rst diff --git a/Misc/NEWS.d/next/Build/2026-08-07-00-00-00.gh-issue-155321.pythonh-posix.rst b/Misc/NEWS.d/next/Build/2026-08-07-00-00-00.gh-issue-155321.pythonh-posix.rst new file mode 100644 index 000000000000000..61b98ee2b297db7 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-08-07-00-00-00.gh-issue-155321.pythonh-posix.rst @@ -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. diff --git a/configure b/configure index 836eb88e4cdb6e5..1a5b4b59fadb8a6 100755 --- a/configure +++ b/configure @@ -4809,7 +4809,7 @@ printf "%s\n" "#define _XOPEN_SOURCE_EXTENDED 1" >>confdefs.h -printf "%s\n" "#define _POSIX_C_SOURCE 202405L" >>confdefs.h +printf "%s\n" "#define _PYTHON_POSIX_C_SOURCE 1" >>confdefs.h # Defining _POSIX_C_SOURCE and _XOPEN_SOURCE hides C23 library diff --git a/configure.ac b/configure.ac index 3a9841b1e7d0747..f113a3fd2c7b575 100644 --- a/configure.ac +++ b/configure.ac @@ -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*/ ]) @@ -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]) # Defining _POSIX_C_SOURCE and _XOPEN_SOURCE hides C23 library # declarations on FreeBSD (e.g. sinpi() in math.h) when compiling diff --git a/pyconfig.h.in b/pyconfig.h.in index 691c6c0d9feb6d0..1db724cbd85de78 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -2161,8 +2161,8 @@ /* 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 to configure _POSIX_C_SOURCE in pyconfig.h */ +#undef _PYTHON_POSIX_C_SOURCE /* Define if you have POSIX threads, and your system does not define that. */ #undef _POSIX_THREADS @@ -2263,5 +2263,13 @@ #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ #endif -#endif /*Py_PYCONFIG_H*/ +/* 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*/ From 69983c8e106cb633407c30899082ca14b0edf28e Mon Sep 17 00:00:00 2001 From: RealBhupesh Date: Fri, 7 Aug 2026 20:01:25 +0530 Subject: [PATCH 2/2] gh-155321: Regenerate pyconfig.h.in --- pyconfig.h.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyconfig.h.in b/pyconfig.h.in index 1db724cbd85de78..159a9b73075a5cd 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -2161,15 +2161,15 @@ /* Define on NetBSD to activate all library features */ #undef _NETBSD_SOURCE -/* Define to configure _POSIX_C_SOURCE in pyconfig.h */ -#undef _PYTHON_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 @@ -2273,3 +2273,4 @@ #endif #endif /*Py_PYCONFIG_H*/ +