You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-133164: Add PyUnstable_Object_IsUniqueReferencedTemporary C API (gh-133170)
After gh-130704, the interpreter replaces some uses of `LOAD_FAST` with
`LOAD_FAST_BORROW` which avoid incref/decrefs by "borrowing" references
on the interpreter stack when the bytecode compiler can determine that
it's safe.
This change broke some checks in C API extensions that relied on
`Py_REFCNT()` of `1` to determine if it's safe to modify an object
in-place. Objects may have a reference count of one, but still be
referenced further up the interpreter stack due to borrowing of
references.
This provides a replacement function for those checks.
`PyUnstable_Object_IsUniqueReferencedTemporary` is more conservative:
it checks that the object has a reference count of one and that it exists as a
unique strong reference in the interpreter's stack of temporary
variables in the top most frame.
See also:
* numpy/numpy#28681
Co-authored-by: Pieter Eendebak <[email protected]>
Co-authored-by: T. Wouters <[email protected]>
Co-authored-by: mpage <[email protected]>
Co-authored-by: Mark Shannon <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
0 commit comments