@@ -613,6 +613,38 @@ Object Protocol
613613
614614 .. versionadded:: 3.14
615615
616+ .. c:function:: int PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *obj)
617+
618+ Check if *obj * is a unique temporary object.
619+ Returns ``1 `` if *obj * is known to be a unique temporary object,
620+ and ``0 `` otherwise. This function cannot fail, but the check is
621+ conservative, and may return ``0 `` in some cases even if *obj * is a unique
622+ temporary object.
623+
624+ If an object is a unique temporary, it is guaranteed that the current code
625+ has the only reference to the object. For arguments to C functions, this
626+ should be used instead of checking if the reference count is ``1 ``. Starting
627+ with Python 3.14, the interpreter internally avoids some reference count
628+ modifications when loading objects onto the operands stack by
629+ :term: `borrowing <borrowed reference> ` references when possible, which means
630+ that a reference count of ``1 `` by itself does not guarantee that a function
631+ argument uniquely referenced.
632+
633+ In the example below, ``my_func `` is called with a unique temporary object
634+ as its argument::
635+
636+ my_func([1, 2, 3])
637+
638+ In the example below, ``my_func `` is **not ** called with a unique temporary
639+ object as its argument, even if its refcount is ``1 ``::
640+
641+ my_list = [1, 2, 3]
642+ my_func(my_list)
643+
644+ See also the function :c:func: `Py_REFCNT `.
645+
646+ .. versionadded :: 3.14
647+
616648.. c :function :: int PyUnstable_IsImmortal (PyObject *obj)
617649
618650 This function returns non-zero if *obj * is :term: `immortal `, and zero
@@ -705,3 +737,21 @@ Object Protocol
705737 caller must hold a :term: `strong reference ` to *obj * when calling this.
706738
707739 .. versionadded :: 3.14
740+
741+ .. c :function :: int PyUnstable_Object_IsUniquelyReferenced (PyObject *op)
742+
743+ Determine if *op * only has one reference.
744+
745+ On GIL-enabled builds, this function is equivalent to
746+ :c:expr: `Py_REFCNT(op) == 1 `.
747+
748+ On a :term: `free threaded <free threading> ` build, this checks if *op *'s
749+ :term: `reference count ` is equal to one and additionally checks if *op *
750+ is only used by this thread. :c:expr: `Py_REFCNT(op) == 1 ` is **not **
751+ thread-safe on free threaded builds; prefer this function.
752+
753+ The caller must hold an :term: `attached thread state `, despite the fact
754+ that this function doesn't call into the Python interpreter. This function
755+ cannot fail.
756+
757+ .. versionadded :: 3.14
0 commit comments