[WIP] bpo-42294: Add Py_SetRef() and Py_XSetRef()#23209
[WIP] bpo-42294: Add Py_SetRef() and Py_XSetRef()#23209vstinner wants to merge 2 commits intopython:masterpython/cpython:masterfrom vstinner:setrefCopy head branch name to clipboard
Conversation
Add Py_SetRef() and Py_XSetRef() functions to set a strong reference to a new object without creating a temporary dangling pointer. Rewrite the Py_SETREF() and Py_XSETREF() macros using respectively Py_SetRef() and Py_XSetRef() functions. Rewrite the Py_CLEAR() macro using the Py_XSetRef() public.
|
This change exposes Py_SETREF() and Py_XSETREF() macros as regular functions to allow using them in extension modules which cannot use the C preprocessor, like extensions written in Rust. It also adds Py_SetRef() and Py_XSetRef() as regular functions part of the limited C API and the stable ABI, whereas Py_SETREF() and Py_XSETREF() are excluded from the limited C API. The Py_SETREF() and Py_XSETREF() macros were added in 2016 by @serhiy-storchaka in bpo-26200 with the commit 57a01d3. |
|
I am not sure about this change really helps Rust, PyPy, HPy, etc. |
There was no discussion about that. I prefer to convert this PR to a draft until I have more time to explain the overall rationale for https://bugs.python.org/issue42294 Also, Serhiy wrote that Py_SETREF() had some flaws, I didn't know that. I will have to dig into old discussions. |
|
This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
|
This PR is stale because it has been open for 30 days with no activity. |
|
I close this PR since I failed to prove that it's useful for Rust, PyPy or HPy. |
Add Py_SetRef() and Py_XSetRef() functions to set a strong reference
to a new object without creating a temporary dangling pointer.
Rewrite the Py_SETREF() and Py_XSETREF() macros using respectively
Py_SetRef() and Py_XSetRef() functions.
Rewrite the Py_CLEAR() macro using the Py_XSetRef() public.
https://bugs.python.org/issue42294