diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-05-08 16:31:23 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2019-05-08 16:31:23 (GMT) |
commit | 94a64e9cd411a87514b68082c1c437eb3b49dfb9 (patch) | |
tree | e7888a142edbe85f294e5859077ecd7400ef4675 /Python/import.c | |
parent | 85225b6a58a516c50c055d5114668ed2fcdcda8c (diff) | |
download | cpython-94a64e9cd411a87514b68082c1c437eb3b49dfb9.zip cpython-94a64e9cd411a87514b68082c1c437eb3b49dfb9.tar.gz cpython-94a64e9cd411a87514b68082c1c437eb3b49dfb9.tar.bz2 |
bpo-24048: Save the live exception during import.c's remove_module() (GH-13005)
Save the live exception during the course of remove_module().
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Python/import.c b/Python/import.c index b03bc98..9290f39 100644 --- a/Python/import.c +++ b/Python/import.c @@ -837,14 +837,18 @@ PyImport_AddModule(const char *name) static void remove_module(PyObject *name) { + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); PyObject *modules = PyImport_GetModuleDict(); + if (!PyMapping_HasKey(modules, name)) { + goto out; + } if (PyMapping_DelItem(modules, name) < 0) { - if (!PyMapping_HasKey(modules, name)) { - return; - } Py_FatalError("import: deleting existing key in " "sys.modules failed"); } +out: + PyErr_Restore(type, value, traceback); } |