diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-05 14:02:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-05 14:02:12 (GMT) |
commit | 53a03aafd5812018a3821a2e83063fd3d6cd2576 (patch) | |
tree | c38adba5e60f412a36ea31736fb6265b2f754a40 /Doc/c-api/refcounting.rst | |
parent | 80449f243b13311d660eab3a751648029bcdd833 (diff) | |
download | cpython-53a03aafd5812018a3821a2e83063fd3d6cd2576.zip cpython-53a03aafd5812018a3821a2e83063fd3d6cd2576.tar.gz cpython-53a03aafd5812018a3821a2e83063fd3d6cd2576.tar.bz2 |
bpo-42262: Add Py_NewRef() and Py_XNewRef() (GH-23152)
Added Py_NewRef() and Py_XNewRef() functions to increment the reference
count of an object and return the object.
Diffstat (limited to 'Doc/c-api/refcounting.rst')
-rw-r--r-- | Doc/c-api/refcounting.rst | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Doc/c-api/refcounting.rst b/Doc/c-api/refcounting.rst index 0df12c6..b15c0e6 100644 --- a/Doc/c-api/refcounting.rst +++ b/Doc/c-api/refcounting.rst @@ -16,12 +16,43 @@ objects. Increment the reference count for object *o*. The object must not be ``NULL``; if you aren't sure that it isn't ``NULL``, use :c:func:`Py_XINCREF`. + See also :c:func:`Py_NewRef`. + .. c:function:: void Py_XINCREF(PyObject *o) Increment the reference count for object *o*. The object may be ``NULL``, in which case the macro has no effect. + See also :c:func:`Py_XNewRef`. + + +.. c:function:: PyObject* Py_NewRef(PyObject *o) + + Increment the reference count of the object *o* and return the object *o*. + + The object *o* must not be ``NULL``. + + For example:: + + Py_INCREF(obj); + self->attr = obj; + + can be written as:: + + self->attr = Py_NewRef(obj); + + .. versionadded:: 3.10 + + +.. c:function:: PyObject* Py_XNewRef(PyObject *o) + + Similar to :c:func:`Py_NewRef`, but the object *o* can be NULL. + + If the object *o* is ``NULL``, the function just returns ``NULL``. + + .. versionadded:: 3.10 + .. c:function:: void Py_DECREF(PyObject *o) |