summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-02-18 07:52:32 -0800
committerAntoine Pitrou <pitrou@free.fr>2019-02-18 15:52:32 +0000
commit3129432845948fdcab1e05042e99a19e9e2c3c71 (patch)
tree9084b4be71d8d4b85bbaaea39e0d199743ffbed2 /Modules
parent0e379d43acc25277f02262212932d3c589a2031b (diff)
downloadcpython-git-3129432845948fdcab1e05042e99a19e9e2c3c71.tar.gz
bpo-34572: change _pickle unpickling to use import rather than retrieving from sys.modules (GH-9047) (GH-11921)
Fix C implementation of pickle.loads to use importlib's locking mechanisms, and thereby avoid using partially-loaded modules. (cherry picked from commit 4371c0a9c0848f7a0947d43f26f234842b41efdf) Co-authored-by: tjb900 <ozburgess@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_pickle.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 60ef921521..15e15cdf45 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -6636,13 +6636,13 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self,
}
}
- module = PyImport_GetModule(module_name);
+ /*
+ * we don't use PyImport_GetModule here, because it can return partially-
+ * initialised modules, which then cause the getattribute to fail.
+ */
+ module = PyImport_Import(module_name);
if (module == NULL) {
- if (PyErr_Occurred())
- return NULL;
- module = PyImport_Import(module_name);
- if (module == NULL)
- return NULL;
+ return NULL;
}
global = getattribute(module, global_name, self->proto >= 4);
Py_DECREF(module);