Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-111506: Implement Py_REFCNT() as opaque function call#112747
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
vstinner commented Dec 5, 2023 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
In the limited C API version 3.13, the Py_REFCNT() function is now implemented as an opaque function call.
vstinner commented Dec 5, 2023
See also discussion #112553 |
vstinner commented Dec 5, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
With this change, all functions reading/setting a Python object reference count go through opaque functions calls in the limited C API version 3.13 or newer:
So implementation details such as immortal objects (PEP 638) and free threading (PEP 703) "deferred reference counting" are no longer leaked at the ABI level. |
encukou commented Dec 5, 2023
I don't think |
vstinner commented Dec 5, 2023
The Py_REFCNT() macro (now it's a static inline function) is part of the limited C API since Python 3.2 (PEP 384). This change only fix its implementation to keep the backward compatibility at the API level. Currently, . You can build existing C extensions without having to change their C code. You just have to target the limited C API version 3.13 if you want to support the free threading build. Currently, building You can test locally with this change: |
encukou commented Dec 5, 2023
Oh, I see. So, we're removing Is there a reason to name the function |
vstinner commented Dec 5, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
This PR doesn't change PyObject.ob_refcnt. We might need to change it to fully implement free threading, but it's wider than the scope of this small change which is backward compatible (EDIT: compatible!).
I don't think that a regular function and a static inline functions can have the same name. With macros, it's possible to reuse the same name, but I don't want to use a macro here. Py_INCREF() and Py_SET_REFCNT() have a similiar design: call an opaque function which has a different name and is only exposed as ABI only in the stable ABI. |
encukou commented Dec 6, 2023
Please discuss at capi-workgroup/api-evolution#18, which has an example of how to do this.
Not even the simple alias macro,
Yeah, that's the bug I was talking about. It's guideline issue 18 again: “All functions should be exported as proper symbols, so they are usable without a C preprocessor/parser.” With this PR, |
vstinner commented Dec 20, 2023
Apparently, there is a discussion/disagreement on the API/name in the ABI. I prefer to close the PR until a decision is taken. |
In the limited C API version 3.13, the Py_REFCNT() function is now implemented as an opaque function call.
--disable-gilbuilds are not compatible with the limited API #111506