summaryrefslogtreecommitdiffstats
path: root/Doc/glossary.rst
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-11-09 12:40:47 (GMT)
committerGitHub <noreply@github.com>2020-11-09 12:40:47 (GMT)
commit23c5f93b83f78f295313e137011edb18b24c37c2 (patch)
tree38cc104221c9e283bdb81f9511abe4fced97d67d /Doc/glossary.rst
parenta117167d8dc8fa673a4646f509551c7950f824e5 (diff)
downloadcpython-23c5f93b83f78f295313e137011edb18b24c37c2.zip
cpython-23c5f93b83f78f295313e137011edb18b24c37c2.tar.gz
cpython-23c5f93b83f78f295313e137011edb18b24c37c2.tar.bz2
bpo-42294: Add borrowed/strong reference to doc glossary (GH-23206)
Add "borrowed reference" and "strong reference" to the documentation glossary. Enhance also Py_INCREF() and Py_NewRef() documentation.
Diffstat (limited to 'Doc/glossary.rst')
-rw-r--r--Doc/glossary.rst24
1 files changed, 24 insertions, 0 deletions
diff --git a/Doc/glossary.rst b/Doc/glossary.rst
index 506973e..b410585 100644
--- a/Doc/glossary.rst
+++ b/Doc/glossary.rst
@@ -158,6 +158,18 @@ Glossary
See also :term:`text file` for a file object able to read and write
:class:`str` objects.
+ borrowed reference
+ In the Python's C API, a borrowed reference is a reference to an object.
+ It does not modify the object reference count. It becomes a dangling
+ pointer if the object is destroyed. For example, a garbage collection can
+ remove the last :term:`strong reference` to the object and so destroy it.
+
+ Calling :c:func:`Py_INCREF` on the :term:`borrowed reference` is
+ recommended to convert it to a :term:`strong reference` in-place, except
+ if the object cannot be destroyed before the last usage of the borrowed
+ reference. The :c:func:`Py_NewRef` function can be used to create a new
+ :term:`strong reference`.
+
bytes-like object
An object that supports the :ref:`bufferobjects` and can
export a C-:term:`contiguous` buffer. This includes all :class:`bytes`,
@@ -1100,6 +1112,18 @@ Glossary
an :term:`expression` or one of several constructs with a keyword, such
as :keyword:`if`, :keyword:`while` or :keyword:`for`.
+ strong reference
+ In the Python's C API, a strong reference is a reference to an object
+ which increments object reference count when it is created and
+ decrements the object reference count when it is deleted.
+
+ The :c:func:`Py_NewRef` function can be used to create a strong reference
+ to an object. Usually, the :c:func:`Py_DECREF` function must be called on
+ the strong reference before exiting the scope of the strong reference, to
+ avoid leaking one reference.
+
+ See also :term:`borrowed reference`.
+
text encoding
A codec which encodes Unicode strings to bytes.