Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-28411: Isolate PyInterpreterState.modules #3575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Replace usage of interp->modules with PyImport_GetModuleDict().
  • Loading branch information
ericsnowcurrently committed Sep 14, 2017
commit ad8c082fa07bca377a5ea646bdaab17837bd5bb4
4 changes: 2 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3902,7 +3902,6 @@ import_copyreg(void)
{
PyObject *copyreg_str;
PyObject *copyreg_module;
PyInterpreterState *interp = PyThreadState_GET()->interp;
_Py_IDENTIFIER(copyreg);

copyreg_str = _PyUnicode_FromId(&PyId_copyreg);
Expand All @@ -3914,7 +3913,8 @@ import_copyreg(void)
by storing a reference to the cached module in a static variable, but
this broke when multiple embedded interpreters were in use (see issue
#17408 and #19088). */
copyreg_module = PyDict_GetItemWithError(interp->modules, copyreg_str);
PyObject *modules = PyImport_GetModuleDict();
copyreg_module = PyDict_GetItemWithError(modules, copyreg_str);
if (copyreg_module != NULL) {
Py_INCREF(copyreg_module);
return copyreg_module;
Expand Down
8 changes: 5 additions & 3 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ PyImport_Cleanup(void)
Py_ssize_t pos;
PyObject *key, *value, *dict;
PyInterpreterState *interp = PyThreadState_GET()->interp;
PyObject *modules = interp->modules;
PyObject *modules = PyImport_GetModuleDict();
PyObject *weaklist = NULL;
const char * const *p;

Expand Down Expand Up @@ -1543,7 +1543,8 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
Py_INCREF(abs_name);
}

mod = PyDict_GetItem(interp->modules, abs_name);
PyObject *modules = PyImport_GetModuleDict();
mod = PyDict_GetItem(modules, abs_name);
if (mod != NULL && mod != Py_None) {
_Py_IDENTIFIER(__spec__);
_Py_IDENTIFIER(_initializing);
Expand Down Expand Up @@ -1630,7 +1631,8 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
goto error;
}

final_mod = PyDict_GetItem(interp->modules, to_return);
PyObject *modules = PyImport_GetModuleDict();
final_mod = PyDict_GetItem(modules, to_return);
Py_DECREF(to_return);
if (final_mod == NULL) {
PyErr_Format(PyExc_KeyError,
Expand Down
5 changes: 2 additions & 3 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1908,9 +1908,8 @@ wait_for_thread_shutdown(void)
{
_Py_IDENTIFIER(_shutdown);
PyObject *result;
PyThreadState *tstate = PyThreadState_GET();
PyObject *threading = PyMapping_GetItemString(tstate->interp->modules,
"threading");
PyObject *modules = PyImport_GetModuleDict();
PyObject *threading = PyMapping_GetItemString(modules, "threading");
if (threading == NULL) {
/* threading not imported */
PyErr_Clear();
Expand Down
5 changes: 3 additions & 2 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ static PyObject *
sys_displayhook(PyObject *self, PyObject *o)
{
PyObject *outf;
PyInterpreterState *interp = PyThreadState_GET()->interp;
PyObject *modules = interp->modules;
PyObject *modules = PyImport_GetModuleDict();
if (modules == NULL)
return NULL;
PyObject *builtins;
static PyObject *newline = NULL;
int err;
Expand Down