Skip to content
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
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed May 18, 2024
commit 5ae49e3d75ed30218f4b7d034c3ac518f29fd84b
27 changes: 7 additions & 20 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ list_item_impl(PyListObject *self, Py_ssize_t idx)
if (!valid_index(idx, size)) {
goto exit;
}
#ifdef Py_GIL_DISABLED
item = _Py_NewRefWithLock(self->ob_item[idx]);
#else
item = Py_NewRef(self->ob_item[idx]);
#endif
exit:
Py_END_CRITICAL_SECTION();
return item;
Expand Down Expand Up @@ -655,28 +659,11 @@ list_item(PyObject *aa, Py_ssize_t i)
PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
return NULL;
}
PyObject *item;
#ifdef Py_GIL_DISABLED
Comment thread
mpage marked this conversation as resolved.
PyObject **ob_item = _Py_atomic_load_ptr(&a->ob_item);
item = _Py_atomic_load_ptr(&ob_item[i]);
if (item && _Py_TryIncrefCompare(&ob_item[i], item)) {
if (ob_item != _Py_atomic_load_ptr(&a->ob_item)) {
Py_DECREF(item);
goto retry;
}
return item;
}
retry:
#endif
Py_BEGIN_CRITICAL_SECTION(a);
#ifdef Py_GIL_DISABLED
if (!_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {
_PyObject_GC_SET_SHARED(a);
}
return list_get_item_ref(a, i);
Comment thread
mpage marked this conversation as resolved.
Outdated
#else
return Py_NewRef(a->ob_item[i]);
#endif
item = Py_NewRef(a->ob_item[i]);
Py_END_CRITICAL_SECTION();
return item;
}

static PyObject *
Expand Down