-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
gh-111506: Implement Py_REFCNT() as opaque function call #112747
Conversation
In the limited C API version 3.13, the Py_REFCNT() function is now implemented as an opaque function call.
d52b1e9
to
4fd7ed6
Compare
See also discussion #112553 |
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. |
I don't think |
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:
|
Oh, I see. So, we're removing Is there a reason to name the function |
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. |
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, |
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-gil
builds are not compatible with the limited API #111506