Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PyList_GetItemRef, a variant of PyList_GetItem that returns a strong reference #114329

Closed
Tracked by #108219
colesbury opened this issue Jan 19, 2024 · 3 comments
Closed
Tracked by #108219
Labels

Comments

@colesbury
Copy link
Contributor

colesbury commented Jan 19, 2024

Feature or enhancement

The free-threaded builds need a variant of PyList_GetItem that returns a strong reference instead of a borrowed reference for thread-safety reasons. PEP 703 proposed PyList_FetchItem, but since then PyDict_GetItemRef and functions with similar signatures have been added.

This proposes PyList_GetItemRef with the following signature:

PyObject *PyList_GetItemRef(PyObject *list, Py_ssize_t index)

Return a strong reference to the object at position index in the list pointed to by list. If index is out of bounds (<0 or >=len(list)), return NULL and set an IndexError. If list is not a list instance, return NULL and set a TypeError.

Linked PRs

@colesbury
Copy link
Contributor Author

C-API working group issue: capi-workgroup/decisions#9

@Eclips4
Copy link
Member

Eclips4 commented Jan 19, 2024

Just FYI, feature requests do not need version label :)

@Eclips4 Eclips4 removed the 3.13 bugs and security fixes label Jan 19, 2024
colesbury added a commit to colesbury/cpython that referenced this issue Jan 23, 2024
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()`.
colesbury added a commit to colesbury/cpython that referenced this issue Jan 30, 2024
encukou pushed a commit that referenced this issue Feb 2, 2024
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()`.
@encukou
Copy link
Member

encukou commented Feb 2, 2024

Thank you!

@encukou encukou closed this as completed Feb 2, 2024
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
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()`.
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this issue Feb 14, 2024
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()`.
vstinner added a commit to vstinner/cpython that referenced this issue Apr 3, 2024
vstinner added a commit to vstinner/cpython that referenced this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants