summaryrefslogtreecommitdiff
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-11-12 14:41:32 +0530
committerGitHub <noreply@github.com>2022-11-12 10:11:32 +0100
commit504e12272b19395a3c59631a20a94e3323af78e5 (patch)
tree6b3dc7c864c15d620493a063b52432edada20f1d /Modules/arraymodule.c
parentaa874326d86734606a1930e7f48e2ee204cae0b6 (diff)
downloadcpython-git-504e12272b19395a3c59631a20a94e3323af78e5.tar.gz
GH-81057: Remove static state from arraymodule (#99409)
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index d60cf26788..8013c5ce6d 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -58,6 +58,8 @@ typedef struct {
PyTypeObject *ArrayType;
PyTypeObject *ArrayIterType;
+ PyObject *array_reconstructor;
+
PyObject *str_read;
PyObject *str_write;
PyObject *str___dict__;
@@ -2191,17 +2193,17 @@ 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)) {
@@ -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);