Skip to content

Commit f9b8d15

Browse files
committed
gh-155321: Avoid Python.h POSIX macro redefinition
1 parent 7c653e2 commit f9b8d15

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allow :file:`Python.h` to be included after system headers that define
2+
``_POSIX_C_SOURCE`` without causing a macro redefinition diagnostic.

configure

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ AH_BOTTOM([
237237
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
238238
#endif
239239
240+
/* Define _POSIX_C_SOURCE only when it was not defined by an earlier
241+
system-header include. */
242+
#ifdef _PYTHON_POSIX_C_SOURCE
243+
# ifndef _POSIX_C_SOURCE
244+
# define _POSIX_C_SOURCE 202405L
245+
# endif
246+
# undef _PYTHON_POSIX_C_SOURCE
247+
#endif
248+
240249
#endif /*Py_PYCONFIG_H*/
241250
])
242251

@@ -930,8 +939,8 @@ then
930939
AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1],
931940
[Define to activate Unix95-and-earlier features])
932941

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

936945
# Defining _POSIX_C_SOURCE and _XOPEN_SOURCE hides C23 library
937946
# declarations on FreeBSD (e.g. sinpi() in math.h) when compiling

pyconfig.h.in

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,8 +2161,8 @@
21612161
/* Define on NetBSD to activate all library features */
21622162
#undef _NETBSD_SOURCE
21632163

2164-
/* Define to activate features from IEEE Std 1003.1-2024 */
2165-
#undef _POSIX_C_SOURCE
2164+
/* Define to configure _POSIX_C_SOURCE in pyconfig.h */
2165+
#undef _PYTHON_POSIX_C_SOURCE
21662166

21672167
/* Define if you have POSIX threads, and your system does not define that. */
21682168
#undef _POSIX_THREADS
@@ -2263,5 +2263,13 @@
22632263
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
22642264
#endif
22652265

2266-
#endif /*Py_PYCONFIG_H*/
2266+
/* Define _POSIX_C_SOURCE only when it was not defined by an earlier
2267+
system-header include. */
2268+
#ifdef _PYTHON_POSIX_C_SOURCE
2269+
# ifndef _POSIX_C_SOURCE
2270+
# define _POSIX_C_SOURCE 202405L
2271+
# endif
2272+
# undef _PYTHON_POSIX_C_SOURCE
2273+
#endif
22672274

2275+
#endif /*Py_PYCONFIG_H*/

0 commit comments

Comments
 (0)