summaryrefslogtreecommitdiffstats
path: root/Modules/_pickle.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2017-09-14 06:46:04 (GMT)
committerGitHub <noreply@github.com>2017-09-14 06:46:04 (GMT)
commit93c92f7d1dbb6e7e472f1d0444c6968858113de2 (patch)
tree031230f9b0cf2e8a8ef21f7fc40c4f5f98d20c6c /Modules/_pickle.c
parent13ad3b7a82bf56d803fbe48ee5df6c4b08986c78 (diff)
downloadcpython-93c92f7d1dbb6e7e472f1d0444c6968858113de2.zip
cpython-93c92f7d1dbb6e7e472f1d0444c6968858113de2.tar.gz
cpython-93c92f7d1dbb6e7e472f1d0444c6968858113de2.tar.bz2
bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)
PR #1638, for bpo-28411, causes problems in some (very) edge cases. Until that gets sorted out, we're reverting the merge. PR #3506, a fix on top of #1638, is also getting reverted.
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r--Modules/_pickle.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index bcbe4ac..3165b4e 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -6425,7 +6425,9 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self,
/*[clinic end generated code: output=becc08d7f9ed41e3 input=e2e6a865de093ef4]*/
{
PyObject *global;
+ PyObject *modules_dict;
PyObject *module;
+ _Py_IDENTIFIER(modules);
/* Try to map the old names used in Python 2.x to the new ones used in
Python 3.x. We do this only with old pickle protocols and when the
@@ -6482,7 +6484,13 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self,
}
}
- module = PyImport_GetModule(module_name);
+ modules_dict = _PySys_GetObjectId(&PyId_modules);
+ if (modules_dict == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules");
+ return NULL;
+ }
+
+ module = PyDict_GetItemWithError(modules_dict, module_name);
if (module == NULL) {
if (PyErr_Occurred())
return NULL;
@@ -6490,11 +6498,11 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self,
if (module == NULL)
return NULL;
global = getattribute(module, global_name, self->proto >= 4);
+ Py_DECREF(module);
}
else {
global = getattribute(module, global_name, self->proto >= 4);
}
- Py_DECREF(module);
return global;
}