mirror of https://github.com/python/cpython.git
GH-81057: Remove static state from arraymodule (#99409)
This commit is contained in:
parent
aa874326d8
commit
504e12272b
|
@ -58,6 +58,8 @@ typedef struct {
|
|||
PyTypeObject *ArrayType;
|
||||
PyTypeObject *ArrayIterType;
|
||||
|
||||
PyObject *array_reconstructor;
|
||||
|
||||
PyObject *str_read;
|
||||
PyObject *str_write;
|
||||
PyObject *str___dict__;
|
||||
|
@ -2191,18 +2193,18 @@ array_array___reduce_ex___impl(arrayobject *self, PyTypeObject *cls,
|
|||
PyObject *array_str;
|
||||
int typecode = self->ob_descr->typecode;
|
||||
int mformat_code;
|
||||
static PyObject *array_reconstructor = NULL;
|
||||
long protocol;
|
||||
|
||||
array_state *state = get_array_state_by_class(cls);
|
||||
assert(state != NULL);
|
||||
|
||||
if (array_reconstructor == NULL) {
|
||||
array_reconstructor = _PyImport_GetModuleAttrString(
|
||||
if (state->array_reconstructor == NULL) {
|
||||
state->array_reconstructor = _PyImport_GetModuleAttrString(
|
||||
"array", "_array_reconstructor");
|
||||
if (array_reconstructor == NULL)
|
||||
if (state->array_reconstructor == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PyLong_Check(value)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
|
@ -2252,8 +2254,10 @@ array_array___reduce_ex___impl(arrayobject *self, PyTypeObject *cls,
|
|||
Py_DECREF(dict);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assert(state->array_reconstructor != NULL);
|
||||
result = Py_BuildValue(
|
||||
"O(OCiN)O", array_reconstructor, Py_TYPE(self), typecode,
|
||||
"O(OCiN)O", state->array_reconstructor, Py_TYPE(self), typecode,
|
||||
mformat_code, array_str, dict);
|
||||
Py_DECREF(dict);
|
||||
return result;
|
||||
|
@ -3013,6 +3017,7 @@ array_traverse(PyObject *module, visitproc visit, void *arg)
|
|||
array_state *state = get_array_state(module);
|
||||
Py_VISIT(state->ArrayType);
|
||||
Py_VISIT(state->ArrayIterType);
|
||||
Py_VISIT(state->array_reconstructor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3022,6 +3027,7 @@ array_clear(PyObject *module)
|
|||
array_state *state = get_array_state(module);
|
||||
Py_CLEAR(state->ArrayType);
|
||||
Py_CLEAR(state->ArrayIterType);
|
||||
Py_CLEAR(state->array_reconstructor);
|
||||
Py_CLEAR(state->str_read);
|
||||
Py_CLEAR(state->str_write);
|
||||
Py_CLEAR(state->str___dict__);
|
||||
|
@ -3066,6 +3072,7 @@ array_modexec(PyObject *m)
|
|||
PyObject *typecodes;
|
||||
const struct arraydescr *descr;
|
||||
|
||||
state->array_reconstructor = NULL;
|
||||
/* Add interned strings */
|
||||
ADD_INTERNED(state, read);
|
||||
ADD_INTERNED(state, write);
|
||||
|
|
Loading…
Reference in New Issue