diff --git a/Objects/listobject.c b/Objects/listobject.c index 7070165014f1379..d2f3b2ad352cdb7 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -651,11 +651,18 @@ static PyObject * list_item(PyObject *aa, Py_ssize_t i) { PyListObject *a = (PyListObject *)aa; + PyObject *item; if (!valid_index(i, PyList_GET_SIZE(a))) { PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err)); return NULL; } - PyObject *item; +#ifdef Py_GIL_DISABLED + 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)) { + return item; + } +#endif Py_BEGIN_CRITICAL_SECTION(a); #ifdef Py_GIL_DISABLED if (!_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {