Browse Source

bpo-24048: Save the live exception during import.c's remove_module() (GH-13005)

Save the live exception during the course of remove_module().
pull/13201/head
Zackery Spytz 7 years ago
committed by Nick Coghlan
parent
commit
94a64e9cd4
  1. 1
      Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst
  2. 10
      Python/import.c

1
Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst

@ -0,0 +1 @@
Save the live exception during import.c's ``remove_module()``.

10
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);
}

Loading…
Cancel
Save