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

gh-112087: Make PyList_{Append,Size,GetSlice} to be thread-safe #114651

Merged
merged 7 commits into from
Jan 31, 2024

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Jan 27, 2024

@corona10
Copy link
Member Author

corona10 commented Jan 27, 2024

@colesbury

  • Py_SET_SIZE: Since Py_SET_SIZE is used for mutable collections, it is worth making it the atomic API.
  • PyList_Size: This API becomes the atomic API.
  • _Py_SET_ITEMREF is added: Too many patterns exist in the list object.c, worth adding it as the utility macro. But I'm not sure that it is located in the proper place.
  • PyList_Append, PyList_GetSlice becomes thread-safe.

@corona10 corona10 changed the title gh-112087: Make PyList_{Append,GetItem,Size,GetSlice} to be thread-safe gh-112087: Make PyList_{Append,Size,GetSlice} to be thread-safe Jan 27, 2024
@@ -328,7 +336,7 @@ PyList_Insert(PyObject *op, Py_ssize_t where, PyObject *newitem)
int
_PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem)
{
Py_ssize_t len = PyList_GET_SIZE(self);
Py_ssize_t len = Py_SIZE(self);
Copy link
Member Author

@corona10 corona10 Jan 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only called by _PyList_AppendTakeRef, so it's safe.

Objects/listobject.c Outdated Show resolved Hide resolved
Objects/listobject.c Outdated Show resolved Hide resolved
Objects/listobject.c Outdated Show resolved Hide resolved
Include/object.h Outdated Show resolved Hide resolved
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@corona10 corona10 merged commit 7b9d406 into python:main Jan 31, 2024
30 checks passed
@corona10 corona10 deleted the gh-112087-append branch January 31, 2024 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants