Skip to content

PEP 803: Py_GIL_DISABLED is tested prior to setting, in patchlevel.h #148267

@mgorny

Description

@mgorny

Bug report

Bug description:

I've been trying the PEP 803 changes in 3.15.0a8 with Meson, and I've hit the following build failure:

$ cc -I/usr/include/python3.15t -DPy_LIMITED_API=0x030f0000 limited.c 
In file included from /usr/include/python3.15t/Python.h:79,
                 from limited.c:1:
/usr/include/python3.15t/object.h:162:5: error: unknown type name ‘PyMutex’
  162 |     PyMutex ob_mutex;           // per-object lock
      |     ^~~~~~~
/usr/include/python3.15t/object.h: In function ‘_Py_SET_SIZE_impl’:
/usr/include/python3.15t/object.h:258:5: error: implicit declaration of function ‘_Py_atomic_store_ssize_relaxed’ [-Wimplicit-function-declaration]
  258 |     _Py_atomic_store_ssize_relaxed(&ob->ob_size, size);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/python3.15t/Python.h:80:
/usr/include/python3.15t/refcount.h: In function ‘_Py_IsImmortal’:
/usr/include/python3.15t/refcount.h:129:13: error: implicit declaration of function ‘_Py_atomic_load_uint32_relaxed’ [-Wimplicit-function-declaration]
  129 |     return (_Py_atomic_load_uint32_relaxed(&op->ob_ref_local) ==
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Per the description, setting Py_LIMITED_API=0x030f0000 when building with 3.15t should be sufficient to trigger abi3t build. However, the logic resides in patchlevel.h:

#if defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED) \
&& !defined(Py_TARGET_ABI3T)
# define Py_TARGET_ABI3T Py_LIMITED_API
#endif

which is included before pyconfig.h:

cpython/Include/Python.h

Lines 13 to 14 in eab7dbd

#include "patchlevel.h"
#include "pyconfig.h"

where Py_GIL_DISABLED is declared. As a result, the condition isn't true unless the user explicitly passes -DPy_GIL_DISABLED=1.

CC @encukou @ngoldbaum

CPython versions tested on:

3.15, CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildThe build process and cross-buildinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions