Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--disable-gil builds are not compatible with the limited API #111506

Open
Tracked by #108219
colesbury opened this issue Oct 30, 2023 · 5 comments
Open
Tracked by #108219

--disable-gil builds are not compatible with the limited API #111506

colesbury opened this issue Oct 30, 2023 · 5 comments
Labels
3.13 new features, bugs and security fixes topic-C-API topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@colesbury
Copy link
Contributor

colesbury commented Oct 30, 2023

Bug report

After #110764, --disable-gil builds of CPython 3.13 are (temporarily) not be compatible with the limited API or the stable ABI due to modifications to the PyObject header. For context, this was noted in the "Backwards Compatibility" section of PEP 703.

Based on feedback on the related discuss post and discussions with Gregory Smith, Guido, Petr, and Victor at the core dev sprint, I believe we can make changes to the stable ABI so that extension author can target a single stable ABI that supports CPython 3.7+ and both the default build and the --disable-gil builds of CPython 3.13+.

These changes will require a PEP. This issue is intended just to keep track of the known problem.

The rough idea is:

  1. make a number of macro/inline functions (e.g., Py_SIZE, Py_TYPE, Py_SET_REFCNT, Py_REFCNT) "real" function calls in the stable ABI for CPython 3.13+
  2. When targeting CPython <= 3.12, use dynamic symbol lookup (GetProcAddress on Windows) or weak symbols (on Linux/macOS) to determine at runtime if the active CPython version provides the desired functions. Otherwise, fall back to old definitions of the above functions for CPython <= 3.12.

Linked PRs

@colesbury colesbury added type-bug An unexpected behavior, bug, or error 3.13 new features, bugs and security fixes topic-free-threading labels Oct 30, 2023
@corona10
Copy link
Member

cc @vstinner

vstinner added a commit to vstinner/cpython that referenced this issue Oct 30, 2023
…ted C API

In the limited C API version 3.13. Py_SET_REFCNT() is now implemented
as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.
vstinner added a commit to vstinner/cpython that referenced this issue Oct 30, 2023
…ted C API

In the limited C API version 3.13, Py_SET_REFCNT() function is now
implemented as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.
@vstinner
Copy link
Member

Before creating a whole new ABI, I would like first to avoid __asm__(...); in Include/*.h, in the limited C API. Assembly code is not portable and can cause compilation issues.

A first step for that is to implement Py_SET_REFCNT() as a function call: PR #111508.

vstinner added a commit to vstinner/cpython that referenced this issue Oct 30, 2023
…ted C API

In the limited C API version 3.13, Py_SET_REFCNT() function is now
implemented as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.
@encukou
Copy link
Member

encukou commented Oct 31, 2023

These changes will require a PEP.

Please, could we have the PEP first, then do the changes?

vstinner added a commit that referenced this issue Nov 3, 2023
…API (#111508)

In the limited C API version 3.13, Py_SET_REFCNT() function is now
implemented as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 5, 2023
In the limited C API version 3.13, the Py_REFCNT() function is now
implemented as an opaque function call.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 5, 2023
In the limited C API version 3.13, the Py_REFCNT() function is now
implemented as an opaque function call.
@encukou
Copy link
Member

encukou commented Dec 5, 2023

Please, could we have the PEP first, then do the changes?

@colesbury, do you still plan to write the PEP? Do you need any help?

@colesbury
Copy link
Contributor Author

@encukou, yes I still intend to write the PEP. It just hasn't been as a high a priority as integrating the pieces of PEP 703.

vstinner added a commit to vstinner/cpython that referenced this issue Dec 6, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Dec 6, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Dec 6, 2023
Add  Objects/object_abi.c file and _Py_STABLE_ABI_IMPL macro.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 6, 2023
Export Py_SET_REFCNT() opaque function as "Py_SET_REFCNT" symbol in
the stable ABI.

Add  Objects/object_abi.c file and _Py_STABLE_ABI_IMPL macro.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 6, 2023
Convert Py_SET_REFCNT() and _Py_IsImmortal() static inline functions
to inline functions.

Stable ABI now use "Py_SET_REFCNT" name instead of "_Py_SetRefcnt".
vstinner added a commit to vstinner/cpython that referenced this issue Dec 6, 2023
Convert Py_SET_REFCNT() and _Py_IsImmortal() static inline functions
to inline functions.

_Py_IsImmortal() has to be converted to an inline function, since
non-static Py_SET_REFCNT() function cannot call a static
_Py_IsImmortal() function.

Py_SET_REFCNT() function is now exported as "Py_SET_REFCNT" name in
the stable ABI, instead of "_Py_SetRefcnt".
vstinner added a commit to vstinner/cpython that referenced this issue Dec 6, 2023
Convert Py_SET_REFCNT() and _Py_IsImmortal() static inline functions
to inline functions.

Py_SET_REFCNT() function is now exported as "Py_SET_REFCNT" name in
the stable ABI, instead of "_Py_SetRefcnt".

_Py_IsImmortal() has to be converted to an inline function, since
non-static Py_SET_REFCNT() function cannot call a static
_Py_IsImmortal() function. _Py_IsImmortal() is not part of the stable
ABI.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 7, 2023
Convert Py_SET_REFCNT() and _Py_IsImmortal() static inline functions
to inline functions.

Py_SET_REFCNT() function is now exported as "Py_SET_REFCNT" name in
the stable ABI, instead of "_Py_SetRefcnt".

_Py_IsImmortal(), _Py_IsOwnedByCurrentThread() and _Py_ThreadId()
have to be converted to an inline functions, since non-static
Py_SET_REFCNT() function cannot call a static functions.
_Py_IsImmortal(), _Py_IsOwnedByCurrentThread() and _Py_ThreadId() are
not part of the stable ABI.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 7, 2023
Convert Py_SET_REFCNT() and _Py_IsImmortal() static inline functions
to inline functions.

Py_SET_REFCNT() function is now exported as "Py_SET_REFCNT" name in
the stable ABI, instead of "_Py_SetRefcnt".

_Py_IsImmortal(), _Py_IsOwnedByCurrentThread() and _Py_ThreadId()
have to be converted to an inline functions, since non-static
Py_SET_REFCNT() function cannot call a static functions.
_Py_IsImmortal(), _Py_IsOwnedByCurrentThread() and _Py_ThreadId() are
not part of the stable ABI.
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…ted C API (python#111508)

In the limited C API version 3.13, Py_SET_REFCNT() function is now
implemented as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.
colesbury added a commit to colesbury/cpython that referenced this issue Apr 11, 2024
Issue a build time error if both `Py_LIMITED_API` and `Py_GIL_DISABLED`
are defined.
colesbury added a commit that referenced this issue Apr 11, 2024
…117762)

Issue a build time error if both `Py_LIMITED_API` and `Py_GIL_DISABLED`
are defined.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…ild (python#117762)

Issue a build time error if both `Py_LIMITED_API` and `Py_GIL_DISABLED`
are defined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 new features, bugs and security fixes topic-C-API topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants