cpython/Doc/c-api
Sam Gross f2379535fe
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:

* https://github.com/numpy/numpy/issues/28681

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: mpage <mpage@cs.stanford.edu>
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-05-02 13:24:57 +00:00
..
abstract.rst
allocation.rst gh-129675: Update documentation for tp_basicsize & tp_itemsize (#129850) 2025-03-11 11:21:18 +01:00
apiabiversion.rst
arg.rst gh-132987: Support __index__() for "k" and "K" formats in PyArg_Parse (GH-132988) 2025-04-26 17:14:18 +03:00
bool.rst
buffer.rst gh-132246: Add PEP 688 to C Buffer Protocol docs (#132249) 2025-04-08 10:43:27 -07:00
bytearray.rst
bytes.rst
call.rst
capsule.rst
cell.rst
code.rst
codec.rst
complex.rst gh-128813: hide mixed-mode functions for complex arithmetic from C-API (#131703) 2025-04-22 14:18:18 +02:00
concrete.rst
contextvars.rst
conversion.rst
coro.rst
datetime.rst
descriptor.rst
dict.rst gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990) 2025-03-20 13:06:59 +01:00
exceptions.rst gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990) 2025-03-20 13:06:59 +01:00
file.rst
float.rst gh-130317: Fix test_pack_unpack_roundtrip() and add docs (#133204) 2025-05-01 16:20:36 +02:00
frame.rst
function.rst gh-130169: Fix broken list markup in Doc/c-api/function.rst (#130174) 2025-02-16 13:55:31 +03:00
gcsupport.rst Docs: Fix specifications of gcvisitobjects_t (#132433) 2025-04-12 17:36:02 +02:00
gen.rst
hash.rst
import.rst
index.rst
init.rst gh-132775: Drop PyUnstable_InterpreterState_GetMainModule() (gh-132978) 2025-04-28 12:46:22 -06:00
init_config.rst gh-107954: Add audit event to PyConfig_Set() (#132958) 2025-04-25 18:30:39 +02:00
intro.rst Fix a grammar error in the Py_ALWAYS_INLINE doc (#129304) 2025-04-24 17:20:48 +03:00
iter.rst
iterator.rst
list.rst
long.rst
mapping.rst
marshal.rst
memory.rst gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990) 2025-03-20 13:06:59 +01:00
memoryview.rst
method.rst
module.rst gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990) 2025-03-20 13:06:59 +01:00
monitoring.rst Python 3.14.0a7 2025-04-08 14:20:51 +03:00
none.rst
number.rst
object.rst gh-133164: Add PyUnstable_Object_IsUniqueReferencedTemporary C API (gh-133170) 2025-05-02 13:24:57 +00:00
objimpl.rst
perfmaps.rst gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990) 2025-03-20 13:06:59 +01:00
refcounting.rst gh-133164: Add PyUnstable_Object_IsUniqueReferencedTemporary C API (gh-133170) 2025-05-02 13:24:57 +00:00
reflection.rst gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990) 2025-03-20 13:06:59 +01:00
sequence.rst
set.rst
slice.rst gh-130214: Document PyEllipsis_Type (GH-130215) 2025-02-17 13:56:33 +01:00
stable.rst
structures.rst gh-130711: Document PyBaseObject_Type (GH-130712) 2025-03-03 15:08:05 +01:00
sys.rst gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990) 2025-03-20 13:06:59 +01:00
time.rst gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990) 2025-03-20 13:06:59 +01:00
tuple.rst
type.rst gh-131544: Update docs for PyType_AddWatcher (gh-132015) 2025-04-02 15:04:07 +00:00
typehints.rst
typeobj.rst Fix a typo in c-api/typeobj.rst (#132317) 2025-04-13 07:18:58 +00:00
unicode.rst gh-46236: Document PyUnicodeIter_Type (GH-132925) 2025-04-29 14:23:06 +02:00
utilities.rst
veryhigh.rst
weakref.rst