This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Mishandled _POSIX_C_SOURCE and _XOPEN_SOURCE in pyconfig.h
Type: compile error Stage: needs patch
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: RAW, iritkatriel, koobs, loewis, vstinner
Priority: normal Keywords:

Created on 2013-02-04 05:39 by RAW, last changed 2022-04-11 14:57 by admin.

Messages (8)
msg181309 - (view) Author: RAW (RAW) Date: 2013-02-04 05:39
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:

#define _POSIX_C_SOURCE 200112L


#define _XOPEN_SOURCE 600

For newer versions of Python, the pyconfig.h header specifies:

#define _POSIX_C_SOURCE 200809L


#define _XOPEN_SOURCE 700

The Open Group has documentation about these symbols:

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:

#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L
#warning Python expects -D_POSIX_C_SOURCE=200112L or later
#define _POSIX_C_SOURCE 200112L

and this:

#if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 600
#warning Python expects -D_XOPEN_SOURCE=600 or later
#define _XOPEN_SOURCE 600
msg183910 - (view) Author: RAW (RAW) Date: 2013-03-11 02:11
Any response?
msg185248 - (view) Author: RAW (RAW) Date: 2013-03-25 23:53
Does anyone ever respond to reported issues here?
msg226849 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2014-09-12 22:44
See also:
msg241328 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2015-04-17 10:40
@RAW, can you attach a patch against the default branch please so we can move this forward?
msg400445 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-08-27 23:17
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.
msg400563 - (view) Author: RAW (RAW) Date: 2021-08-29 22:11
Please look at which is used to create configure which will generate pyconfig.h from according to what features are detected in the system.
msg400614 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-08-30 15:01
On my Fedora 34, running ./configure creates pyconfig.h with these values:

$ grep -E '_POSIX_C_SOURCE|_XOPEN_SOURCE' -B1 pyconfig.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 */

Relevant lines in
if test $define_xopen_source = yes
  # X/Open 7, incorporating POSIX.1-2008
            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.
   	    Define to activate Unix95-and-earlier features)

  AC_DEFINE(_POSIX_C_SOURCE, 200809L, Define to activate features from IEEE Stds 1003.1-2008)
Date User Action Args
2022-04-11 14:57:41adminsetgithub: 61322
2021-12-12 19:07:28iritkatrielsetversions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.2, Python 3.3, Python 3.4
2021-08-30 15:01:21vstinnersetmessages: + msg400614
2021-08-29 22:12:58RAWsetresolution: out of date ->
2021-08-29 22:11:50RAWsetstatus: pending -> open

messages: + msg400563
2021-08-27 23:17:57iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg400445

resolution: out of date
2015-04-17 10:40:12koobssetmessages: + msg241328
2014-09-16 09:52:25pitrousetnosy: + loewis
2014-09-12 22:44:05koobssetnosy: + koobs
messages: + msg226849
2013-03-25 23:57:18ezio.melottisetstage: needs patch
versions: - Python 2.6, Python 3.1, Python 3.5
2013-03-25 23:54:22vstinnersetnosy: + vstinner
2013-03-25 23:53:05RAWsetmessages: + msg185248
2013-03-25 23:51:31RAWsetstatus: languishing -> open
2013-03-11 02:11:18RAWsetstatus: open -> languishing

messages: + msg183910
2013-02-04 05:39:07RAWcreate