Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-112087: Make list_{count, index, contains} to be thread-safe. #114916

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

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-112087: Make list_{count, index, contains} to be thread-safe.
  • Loading branch information
corona10 committed Feb 2, 2024
commit 4b8ac83521c30577c4b0cfd3f37f43c30703b7d9
40 changes: 24 additions & 16 deletions 40 Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,18 +478,21 @@ list_length(PyObject *a)
static int
list_contains(PyObject *aa, PyObject *el)
{
PyListObject *a = (PyListObject *)aa;
PyObject *item;
Py_ssize_t i;
int cmp;

for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i) {
item = PyList_GET_ITEM(a, i);
Py_INCREF(item);
cmp = PyObject_RichCompareBool(item, el, Py_EQ);
for (Py_ssize_t i = 0; ; i++) {
PyObject *item = PyList_GetItemRef(aa, i);
if (item == NULL && PyErr_ExceptionMatches(PyExc_IndexError)) {
corona10 marked this conversation as resolved.
Show resolved Hide resolved
// out-of-bounds
PyErr_Clear();
return 0;
}
int cmp = PyObject_RichCompareBool(item, el, Py_EQ);
Py_DECREF(item);
if (cmp != 0) {
return cmp;
}
}
return cmp;
return 0;
}

static PyObject *
Expand Down Expand Up @@ -2737,8 +2740,11 @@ list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
stop = 0;
}
for (i = start; i < stop && i < Py_SIZE(self); i++) {
corona10 marked this conversation as resolved.
Show resolved Hide resolved
PyObject *obj = self->ob_item[i];
Py_INCREF(obj);
PyObject *obj = PyList_GetItemRef((PyObject *)self, i);
if (obj == NULL && PyErr_ExceptionMatches(PyExc_IndexError)) {
PyErr_Clear();
break;
}
int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
Py_DECREF(obj);
if (cmp > 0)
Expand All @@ -2764,15 +2770,17 @@ list_count(PyListObject *self, PyObject *value)
/*[clinic end generated code: output=b1f5d284205ae714 input=3bdc3a5e6f749565]*/
{
Py_ssize_t count = 0;
Py_ssize_t i;

for (i = 0; i < Py_SIZE(self); i++) {
PyObject *obj = self->ob_item[i];
for (Py_ssize_t i = 0; ; i++) {
PyObject *obj = PyList_GetItemRef((PyObject *)self, i);
if (obj == NULL && PyErr_ExceptionMatches(PyExc_IndexError)) {
PyErr_Clear();
break;
}
if (obj == value) {
count++;
Py_DECREF(obj);
continue;
}
Py_INCREF(obj);
int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
Py_DECREF(obj);
if (cmp > 0)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.