diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-02-23 00:23:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-23 00:23:51 (GMT) |
commit | 1f455361ecfb1892e375bdbee813cdf095b6cfb8 (patch) | |
tree | d7def4d5d167965a45c4b0e30bb5a1a0bb5c3b4a /Objects/listobject.c | |
parent | cff4d5c5d29528299ec1ac5b3b3a6f7735577c01 (diff) | |
download | cpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.zip cpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.tar.gz cpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.tar.bz2 |
bpo-46765: Replace Locally Cached Strings with Statically Initialized Objects (gh-31366)
https://bugs.python.org/issue46765
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 1ba1c1b..783ae88 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -15,7 +15,7 @@ class list "PyListObject *" "&PyList_Type" #include "clinic/listobject.c.h" -static PyObject *indexerr = NULL; +_Py_DECLARE_STR(list_err, "list index out of range"); #if PyList_MAXFREELIST > 0 static struct _Py_list_state * @@ -125,10 +125,6 @@ _PyList_Fini(PyInterpreterState *interp) struct _Py_list_state *state = &interp->list; state->numfree = -1; #endif - - if (_Py_IsMainInterpreter(interp)) { - Py_CLEAR(indexerr); - } } /* Print summary info about the state of the optimized allocator */ @@ -238,13 +234,8 @@ 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; - } - PyErr_SetObject(PyExc_IndexError, indexerr); + _Py_DECLARE_STR(list_err, "list index out of range"); + PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err)); return NULL; } return ((PyListObject *)op) -> ob_item[i]; @@ -452,13 +443,7 @@ 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; - } - PyErr_SetObject(PyExc_IndexError, indexerr); + PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err)); return NULL; } Py_INCREF(a->ob_item[i]); |