Skip to content
Merged
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
17 changes: 12 additions & 5 deletions Modules/arraymodule.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,8 @@ typedef struct{
PyTypeObject *ArrayType;
PyTypeObject *ArrayIterType;

PyObject *array_reconstructor;

PyObject *str_read;
PyObject *str_write;
PyObject *str___dict__;
Expand DownExpand Up@@ -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)){
Expand DownExpand Up@@ -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;
Expand DownExpand Up@@ -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;
}

Expand All@@ -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__);
Expand DownExpand Up@@ -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);
Expand Down