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

bpo-43588: fix listobject.c use static variables under building under building Python with --with-experimental-isolated-subinterpreters may cause crash #24972

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
22 changes: 10 additions & 12 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <sys/types.h> /* For size_t */
#endif

_Py_static_string(_indexerr, "list index out of range");

/*[clinic input]
class list "PyListObject *" "&PyList_Type"
[clinic start generated code]*/
Expand Down Expand Up @@ -218,8 +220,6 @@ valid_index(Py_ssize_t i, Py_ssize_t limit)
return (size_t) i < (size_t) limit;
}

static PyObject *indexerr = NULL;

PyObject *
PyList_GetItem(PyObject *op, Py_ssize_t i)
{
Expand All @@ -228,11 +228,10 @@ PyList_GetItem(PyObject *op, Py_ssize_t i)
return NULL;
}
if (!valid_index(i, Py_SIZE(op))) {
if (indexerr == NULL) {
indexerr = PyUnicode_FromString(
"list index out of range");
if (indexerr == NULL)
return NULL;
PyObject *indexerr = _PyUnicode_FromId(&_indexerr); // borrowed ref
if (indexerr == NULL)
{
return NULL;
}
PyErr_SetObject(PyExc_IndexError, indexerr);
return NULL;
Expand Down Expand Up @@ -439,11 +438,10 @@ static PyObject *
list_item(PyListObject *a, Py_ssize_t i)
{
if (!valid_index(i, Py_SIZE(a))) {
if (indexerr == NULL) {
indexerr = PyUnicode_FromString(
"list index out of range");
if (indexerr == NULL)
return NULL;
PyObject *indexerr = _PyUnicode_FromId(&_indexerr); // borrowed ref
if (indexerr == NULL)
{
return NULL;
}
PyErr_SetObject(PyExc_IndexError, indexerr);
return NULL;
Expand Down