From 94a64e9cd411a87514b68082c1c437eb3b49dfb9 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Wed, 8 May 2019 10:31:23 -0600 Subject: bpo-24048: Save the live exception during import.c's remove_module() (GH-13005) Save the live exception during the course of remove_module(). --- Python/import.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Python/import.c') diff --git a/Python/import.c b/Python/import.c index b03bc98773a..9290f39c0ae 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); } -- cgit v1.2.3