mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-28411: Isolate PyInterpreterState.modules (#3575)
A bunch of code currently uses PyInterpreterState.modules directly instead of PyImport_GetModuleDict(). This complicates efforts to make changes relative to sys.modules. This patch switches to using PyImport_GetModuleDict() uniformly. Also, a number of related uses of sys.modules are updated for uniformity for the same reason. Note that this code was already reviewed and merged as part of #1638. I reverted that and am now splitting it up into more focused parts.
This commit is contained in:
parent
8dcf22f442
commit
d393c1b227
10 changed files with 116 additions and 55 deletions
|
@ -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);
|
||||
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue