]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-24048: Save the live exception during import.c's remove_module() (GH-13005)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 29 May 2020 19:35:21 +0000 (12:35 -0700)
committerGitHub <noreply@github.com>
Fri, 29 May 2020 19:35:21 +0000 (12:35 -0700)
Save the live exception during the course of remove_module().
(cherry picked from commit 94a64e9cd411a87514b68082c1c437eb3b49dfb9)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst [new file with mode: 0644]
Python/import.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst b/Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst
new file mode 100644 (file)
index 0000000..27c86a4
--- /dev/null
@@ -0,0 +1 @@
+Save the live exception during import.c's ``remove_module()``.
index 6d014cf5b008fc838b3439a8b684d9ce55c9604e..d436d576eb3cd6a3f209ed98357d2008d5ddb26c 100644 (file)
@@ -827,14 +827,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);
 }