-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[C API] Make Py_TYPE() opaque in limited C API 3.14 #120600
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
Comments
In the limited C API 3.14 and newer, Py_TYPE() and Py_SET_TYPE() are now implemented as opaque function calls to hide implementation details.
In the limited C API 3.14 and newer, Py_TYPE() and Py_SET_TYPE() are now implemented as opaque function calls to hide implementation details. Add _Py_TYPE() and _Py_SET_TYPE() private functions.
I'd prefer if As for Please add tests for the old implementation (getting/setting |
_testcapi has // Ensure that following tests don't modify the object,
// to ensure that Py_DECREF() will not crash.
assert(Py_TYPE(obj) == &PyList_Type);
assert(Py_SIZE(obj) == 0);
// bpo-39573: Test Py_SET_TYPE() and Py_SET_SIZE() functions.
Py_SET_TYPE(obj, &PyList_Type);
Py_SET_SIZE(obj, 0); |
In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
I modified my PR to only reuse |
Sounds good, thanks! I don't think it'll solve thread safety -- |
I also wrote PEP 737 "C API to format a type fully qualified name" to avoid a common usage of Py_TYPE() borrowed reference. (The old usage can lead to a crash, see the PEP!) |
Related change done in Python 3.12: Limited C API: implement Py_INCREF() and Py_DECREF() as function calls. |
In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
…120601) In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
Is there something left to do here? |
Fixed by change 16f8e22. |
There's still |
I suggest to open a new issue. If I understood correctly, Py_SET_TYPE() should not exist in the limited C API, since static types cannot be defined with the limited C API. |
…120601) In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
…120601) In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
…120601) In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
I created an issue for Py_REFCNT(): #124127 |
In the limited C API 3.14 and newer, I propose to change Py_TYPE() and Py_SET_TYPE() implementation to opaque function calls to hide implementation details. I made a similar change for Py_REFCNT() and Py_SET_REFCNT() in Python 3.12.
The problem is that with Free Threading (PEP 703), the implementation of these functions become less trivial than just getting/setting an object member:
_Py_atomic_load_ptr_relaxed()
and_Py_atomic_store_ptr()
must now be called. But I would prefer to not "leak" such implementation detail into the limited C API.cc @colesbury @Fidget-Spinner
Linked PRs
The text was updated successfully, but these errors were encountered: