summaryrefslogtreecommitdiffstats
path: root/Doc/c-api
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-02-02 13:03:15 (GMT)
committerGitHub <noreply@github.com>2024-02-02 13:03:15 (GMT)
commitd0f1307580a69372611d27b04bbf2551dc85a1ef (patch)
treec690e6915eb44d57fc8af1623dc57babe3eca3ab /Doc/c-api
parent0e71a295e9530c939a5efcb45db23cf31e0303b4 (diff)
downloadcpython-d0f1307580a69372611d27b04bbf2551dc85a1ef.zip
cpython-d0f1307580a69372611d27b04bbf2551dc85a1ef.tar.gz
cpython-d0f1307580a69372611d27b04bbf2551dc85a1ef.tar.bz2
gh-114329: Add `PyList_GetItemRef` function (GH-114504)
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets a `TypeError` instead of calling `PyErr_BadInternalCall()`.
Diffstat (limited to 'Doc/c-api')
-rw-r--r--Doc/c-api/list.rst12
1 files changed, 10 insertions, 2 deletions
diff --git a/Doc/c-api/list.rst b/Doc/c-api/list.rst
index c8b64ba..53eb54d 100644
--- a/Doc/c-api/list.rst
+++ b/Doc/c-api/list.rst
@@ -56,13 +56,21 @@ List Objects
Similar to :c:func:`PyList_Size`, but without error checking.
-.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
+.. c:function:: PyObject* PyList_GetItemRef(PyObject *list, Py_ssize_t index)
Return the object at position *index* in the list pointed to by *list*. The
position must be non-negative; indexing from the end of the list is not
- supported. If *index* is out of bounds (<0 or >=len(list)),
+ supported. If *index* is out of bounds (:code:`<0 or >=len(list)`),
return ``NULL`` and set an :exc:`IndexError` exception.
+ .. versionadded:: 3.13
+
+
+.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
+
+ Like :c:func:`PyList_GetItemRef`, but returns a
+ :term:`borrowed reference` instead of a :term:`strong reference`.
+
.. c:function:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i)