You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mishandled _POSIX_C_SOURCE and _XOPEN_SOURCE in pyconfig.h #61322
A POSIX-conforming application should ensure that the feature test macro _POSIX_C_SOURCE is defined before inclusion of any header.
So, having a header file attempting to set _POSIX_C_SOURCE violates this intention.
Yes, I am well aware that the Python documentation says to include Python.h before any standard headers are included. However, this is still problematic.
In particular, it causes trouble for source code that wishes to include the Python headers and wishes to use declarations that are made visible by setting later values for _POSIX_C_SOURCE and _XOPEN_SOURCE.
I would suggest the pyconfig.h be updated to have something like this:
#if !defined(_POSIX_C_SOURCE) ||_POSIX_C_SOURCE<200112L#ifdef_POSIX_C_SOURCE#warning Python expects -D_POSIX_C_SOURCE=200112L or later
#undef _POSIX_C_SOURCE
#endif#define_POSIX_C_SOURCE 200112L
#endif
and this:
#if !defined(_XOPEN_SOURCE) ||_XOPEN_SOURCE<600#ifdef_XOPEN_SOURCE#warning Python expects -D_XOPEN_SOURCE=600 or later
#undef _XOPEN_SOURCE
#endif#define_XOPEN_SOURCE 600
#endif
I can't find pyconfig.h or "#define _POSIX_C_SOURCE" or "#define _XOPEN_SOURCE".
If nobody will object I will soon close this issue as out of date.
Reacted by Paul m. p. Peny
RAW commented on Aug 29, 2021
RAWmannequin
MannequinAuthor
More actions
Please look at configure.ac which is used to create configure which will generate pyconfig.h from pyconfig.h.in according to what features are detected in the system.
On my Fedora 34, running ./configure creates pyconfig.h with these values:
$grep-E'_POSIX_C_SOURCE|_XOPEN_SOURCE'-B1pyconfig.h/* Define to activate features from IEEE Stds 1003.1-2008 */#define_POSIX_C_SOURCE 200809L
--/* Define to the level of X/Open that your system supports */#define_XOPEN_SOURCE 700
--/* Define to activate Unix95-and-earlier features */#define_XOPEN_SOURCE_EXTENDED 1
Relevant lines in configure.ac:
---
if test $define_xopen_source = yes
then
# X/Open 7, incorporating POSIX.1-2008
AC_DEFINE(_XOPEN_SOURCE, 700,
Define to the level of X/Open that your system supports)
# On Tru64 Unix 4.0F, defining _XOPEN_SOURCE also requires# definition of _XOPEN_SOURCE_EXTENDED and _POSIX_C_SOURCE, or else# several APIs are not declared. Since this is also needed in some# cases for HP-UX, we define it globally.AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1,
DefinetoactivateUnix95-and-earlierfeatures)
AC_DEFINE(_POSIX_C_SOURCE, 200809L, DefinetoactivatefeaturesfromIEEEStds1003.1-2008)
fi
Yes, I am well aware that the Python documentation says to include Python.h before any standard headers are included. However, this is still problematic.
It is impossible to do when using a compiler such as nvcc which includes its own headers (which include standard headers) as the first thing.
Activity
RAW commentedon Feb 4, 2013
The header file pyconfig.h mishandles the _POSIX_C_SOURCE and _XOPEN_SOURCE preprocessor macros.
For older versions of Python, the pyconfig.h header specifies:
and:
For newer versions of Python, the pyconfig.h header specifies:
and:
The Open Group has documentation about these symbols:
http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html
In particular, the documentation states:
A POSIX-conforming application should ensure that the feature test macro _POSIX_C_SOURCE is defined before inclusion of any header.
So, having a header file attempting to set _POSIX_C_SOURCE violates this intention.
Yes, I am well aware that the Python documentation says to include Python.h before any standard headers are included. However, this is still problematic.
In particular, it causes trouble for source code that wishes to include the Python headers and wishes to use declarations that are made visible by setting later values for _POSIX_C_SOURCE and _XOPEN_SOURCE.
I would suggest the pyconfig.h be updated to have something like this:
and this:
RAW commentedon Mar 11, 2013
Any response?
RAW commentedon Mar 25, 2013
Does anyone ever respond to reported issues here?
koobs commentedon Sep 12, 2014
See also:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=192365
koobs commentedon Apr 17, 2015
@RAW, can you attach a patch against the default branch please so we can move this forward?
iritkatriel commentedon Aug 27, 2021
I can't find pyconfig.h or "#define _POSIX_C_SOURCE" or "#define _XOPEN_SOURCE".
If nobody will object I will soon close this issue as out of date.
RAW commentedon Aug 29, 2021
Please look at configure.ac which is used to create configure which will generate pyconfig.h from pyconfig.h.in according to what features are detected in the system.
vstinner commentedon Aug 30, 2021
On my Fedora 34, running ./configure creates pyconfig.h with these values:
Relevant lines in configure.ac:
---
if test $define_xopen_source = yes
then
# X/Open 7, incorporating POSIX.1-2008
AC_DEFINE(_XOPEN_SOURCE, 700,
Define to the level of X/Open that your system supports)
lahwaacz commentedon Feb 14, 2026
It is impossible to do when using a compiler such as
nvccwhich includes its own headers (which include standard headers) as the first thing.lahwaacz commentedon Feb 14, 2026
pyconfig.h.incurrently contains:cpython/pyconfig.h.in
Lines 1965 to 1969 in 75d4839
But then this:
cpython/pyconfig.h.in
Lines 2045 to 2046 in 75d4839
cpython/pyconfig.h.in
Lines 2084 to 2088 in 75d4839
pyconfig.hdefines_XOPEN_SOURCEconditionally and unconditionally as well #144870 as a duplicate of this issuefix "_POSIX_C_SOURCE redefined" error and warnings
fix "_POSIX_C_SOURCE redefined" error and warnings (#19340)
py: Fix include order
libcamera v0.7.1