Skip to content

Mishandled _POSIX_C_SOURCE and _XOPEN_SOURCE in pyconfig.h #61322

Open

Description

@RAW
mannequin
BPO 17120
Nosy @loewis, @vstinner, @koobs, @iritkatriel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2013-02-04.05:39:07.814>
labels = ['build', 'library', '3.9', '3.10', '3.11']
title = 'Mishandled _POSIX_C_SOURCE and _XOPEN_SOURCE in pyconfig.h'
updated_at = <Date 2021-12-12.19:07:28.318>
user = 'https://bugs.python.org/RAW'

bugs.python.org fields:

activity = <Date 2021-12-12.19:07:28.318>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2013-02-04.05:39:07.814>
creator = 'RAW'
dependencies = []
files = []
hgrepos = []
issue_num = 17120
keywords = []
message_count = 8.0
messages = ['181309', '183910', '185248', '226849', '241328', '400445', '400563', '400614']
nosy_count = 5.0
nosy_names = ['loewis', 'vstinner', 'koobs', 'RAW', 'iritkatriel']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'compile error'
url = 'https://bugs.python.org/issue17120'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

Activity

  1. RAW commented on Feb 4, 2013

    RAWmannequin
    MannequinAuthor

    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

    and:

    #define _XOPEN_SOURCE 600

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

    #define _POSIX_C_SOURCE 200809L

    and:

    #define _XOPEN_SOURCE 700

    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:

    #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
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    buildThe build process and cross-build
    on Feb 4, 2013
  3. RAW commented on Mar 11, 2013

    RAWmannequin
    MannequinAuthor

    Any response?

  4. added
    staleStale PR or inactive for long period of time.
    on Mar 11, 2013
  5. removed
    staleStale PR or inactive for long period of time.
    on Mar 25, 2013
  6. RAW commented on Mar 25, 2013

    RAWmannequin
    MannequinAuthor

    Does anyone ever respond to reported issues here?

  7. koobs commented on Sep 12, 2014

    @koobs
  8. koobs commented on Apr 17, 2015

    @koobs

    @RAW, can you attach a patch against the default branch please so we can move this forward?

  9. iritkatriel commented on Aug 27, 2021

    @iritkatriel
    Member

    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.

  10. RAW commented on Aug 29, 2021

    RAWmannequin
    MannequinAuthor

    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.

  11. vstinner commented on Aug 30, 2021

    @vstinner
    Member

    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 */
    #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,
       	    Define to activate Unix95-and-earlier features)
    
      AC_DEFINE(_POSIX_C_SOURCE, 200809L, Define to activate features from IEEE Stds 1003.1-2008)
    fi

  12. transferred this issue fromon Apr 10, 2022
  13. lahwaacz commented on Feb 14, 2026

    @lahwaacz

    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.

  14. lahwaacz commented on Feb 14, 2026

    @lahwaacz

    pyconfig.h.in currently contains:

    cpython/pyconfig.h.in

    Lines 1965 to 1969 in 75d4839

    /* Enable X/Open extensions. Define to 500 only if necessary
    to make mbstate_t available. */
    #ifndef _XOPEN_SOURCE
    # undef _XOPEN_SOURCE
    #endif

    But then this:

    cpython/pyconfig.h.in

    Lines 2045 to 2046 in 75d4839

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

    cpython/pyconfig.h.in

    Lines 2084 to 2088 in 75d4839

    /* Define to the level of X/Open that your system supports */
    #undef _XOPEN_SOURCE
    /* Define to activate Unix95-and-earlier features */
    #undef _XOPEN_SOURCE_EXTENDED

  15. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    and removed
    3.11only security fixes
    on Feb 16, 2026
  16. added a commit that references this issue on Mar 8, 2026
  17. added a commit that references this issue on Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15bugs and security fixesbuildThe build process and cross-buildstdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions