Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 504e122

Browse files
GH-81057: Remove static state from arraymodule (#99409)
1 parent aa87432 commit 504e122

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Modules/arraymodule.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ typedef struct {
5858
PyTypeObject *ArrayType;
5959
PyTypeObject *ArrayIterType;
6060

61+
PyObject *array_reconstructor;
62+
6163
PyObject *str_read;
6264
PyObject *str_write;
6365
PyObject *str___dict__;
@@ -2191,17 +2193,17 @@ array_array___reduce_ex___impl(arrayobject *self, PyTypeObject *cls,
21912193
PyObject *array_str;
21922194
int typecode = self->ob_descr->typecode;
21932195
int mformat_code;
2194-
static PyObject *array_reconstructor = NULL;
21952196
long protocol;
21962197

21972198
array_state *state = get_array_state_by_class(cls);
21982199
assert(state != NULL);
21992200

2200-
if (array_reconstructor == NULL) {
2201-
array_reconstructor = _PyImport_GetModuleAttrString(
2201+
if (state->array_reconstructor == NULL) {
2202+
state->array_reconstructor = _PyImport_GetModuleAttrString(
22022203
"array", "_array_reconstructor");
2203-
if (array_reconstructor == NULL)
2204+
if (state->array_reconstructor == NULL) {
22042205
return NULL;
2206+
}
22052207
}
22062208

22072209
if (!PyLong_Check(value)) {
@@ -2252,8 +2254,10 @@ array_array___reduce_ex___impl(arrayobject *self, PyTypeObject *cls,
22522254
Py_DECREF(dict);
22532255
return NULL;
22542256
}
2257+
2258+
assert(state->array_reconstructor != NULL);
22552259
result = Py_BuildValue(
2256-
"O(OCiN)O", array_reconstructor, Py_TYPE(self), typecode,
2260+
"O(OCiN)O", state->array_reconstructor, Py_TYPE(self), typecode,
22572261
mformat_code, array_str, dict);
22582262
Py_DECREF(dict);
22592263
return result;
@@ -3013,6 +3017,7 @@ array_traverse(PyObject *module, visitproc visit, void *arg)
30133017
array_state *state = get_array_state(module);
30143018
Py_VISIT(state->ArrayType);
30153019
Py_VISIT(state->ArrayIterType);
3020+
Py_VISIT(state->array_reconstructor);
30163021
return 0;
30173022
}
30183023

@@ -3022,6 +3027,7 @@ array_clear(PyObject *module)
30223027
array_state *state = get_array_state(module);
30233028
Py_CLEAR(state->ArrayType);
30243029
Py_CLEAR(state->ArrayIterType);
3030+
Py_CLEAR(state->array_reconstructor);
30253031
Py_CLEAR(state->str_read);
30263032
Py_CLEAR(state->str_write);
30273033
Py_CLEAR(state->str___dict__);
@@ -3066,6 +3072,7 @@ array_modexec(PyObject *m)
30663072
PyObject *typecodes;
30673073
const struct arraydescr *descr;
30683074

3075+
state->array_reconstructor = NULL;
30693076
/* Add interned strings */
30703077
ADD_INTERNED(state, read);
30713078
ADD_INTERNED(state, write);

0 commit comments

Comments
 (0)