File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -613,3 +613,19 @@ Object Protocol
613613
614614 .. versionadded:: 3.14
615615
616+ .. c:function:: int PyUnstable_IsImmortal(PyObject *obj)
617+
618+ This function returns ``1 `` if *obj * is :term: `immortal `, and ``0 `` otherwise.
619+
620+ Immortal objects don't care about reference counting, thus they no-op calls to :c:func: `Py_INCREF `
621+ and :c:func: `Py_DECREF `. Some immutable objects such as literal strings, small integers, or special tuples
622+ might be made immortal as an optimization by the interpreter.
623+
624+ On the :term: `free-threaded <free threading> ` build, some objects that support deferred reference counting
625+ (see :c:func: `PyUnstable_Object_EnableDeferredRefcount `) might also be immortalized.
626+
627+ .. note::
628+
629+ Objects that are immortal in one version are not guarunteed to be immortal in another.
630+
631+ .. versionadded:: next
Original file line number Diff line number Diff line change @@ -3155,3 +3155,11 @@ Py_REFCNT(PyObject *ob)
31553155{
31563156 return _Py_REFCNT (ob );
31573157}
3158+
3159+ int
3160+ PyUnstable_IsImmortal (PyObject * op )
3161+ {
3162+ /* Checking a reference count requires a thread state */
3163+ _Py_AssertHoldsTstate ();
3164+ return _Py_IsImmortal (op );
3165+ }
You can’t perform that action at this time.
0 commit comments