Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Look up sys.modules in PyImport_GetModuleDict().
  • Loading branch information
ericsnowcurrently committed Sep 15, 2017
commit 3920902cf54118351a5249166e959f568c28a57d
14 changes: 10 additions & 4 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,17 @@ _PyImport_Fini(void)
PyObject *
PyImport_GetModuleDict(void)
{
PyInterpreterState *interp = PyThreadState_GET()->interp;
if (interp->modules == NULL) {
Py_FatalError("PyImport_GetModuleDict: no module dictionary!");
PyObject *sysdict = PyThreadState_GET()->interp->sysdict;
if (sysdict == NULL) {
Py_FatalError("PyImport_GetModuleDict: no sys module!");
}

_Py_IDENTIFIER(modules);
PyObject *modules = _PyDict_GetItemId(sysdict, &PyId_modules);
if (modules == NULL) {
Py_FatalError("lost sys.modules");
}
return interp->modules;
return modules;
}

/* In some corner cases it is important to be sure that the import
Expand Down