summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2017-09-15 22:35:20 (GMT)
committerGitHub <noreply@github.com>2017-09-15 22:35:20 (GMT)
commit3f9eee6eb4b25fe1926eaa5f00e02344b126f54d (patch)
treec749747e0b4ce492d05c34ad5578b81128be1156 /Python/pylifecycle.c
parente82c034496512139e9ea3f68ceda86c04bc7baab (diff)
downloadcpython-3f9eee6eb4b25fe1926eaa5f00e02344b126f54d.zip
cpython-3f9eee6eb4b25fe1926eaa5f00e02344b126f54d.tar.gz
cpython-3f9eee6eb4b25fe1926eaa5f00e02344b126f54d.tar.bz2
bpo-28411: Support other mappings in PyInterpreterState.modules. (#3593)
The concrete PyDict_* API is used to interact with PyInterpreterState.modules in a number of places. This isn't compatible with all dict subclasses, nor with other Mapping implementations. This patch switches the concrete API usage to the corresponding abstract API calls. We also add a PyImport_GetModule() function (and some other helpers) to reduce a bunch of code duplication.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 5c8cf5b..7adbc29 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -42,6 +42,7 @@ _Py_IDENTIFIER(name);
_Py_IDENTIFIER(stdin);
_Py_IDENTIFIER(stdout);
_Py_IDENTIFIER(stderr);
+_Py_IDENTIFIER(threading);
#ifdef __cplusplus
extern "C" {
@@ -283,7 +284,6 @@ initimport(PyInterpreterState *interp, PyObject *sysmod)
{
PyObject *importlib;
PyObject *impmod;
- PyObject *sys_modules;
PyObject *value;
/* Import _importlib through its frozen version, _frozen_importlib. */
@@ -314,11 +314,7 @@ initimport(PyInterpreterState *interp, PyObject *sysmod)
else if (Py_VerboseFlag) {
PySys_FormatStderr("import _imp # builtin\n");
}
- sys_modules = PyImport_GetModuleDict();
- if (Py_VerboseFlag) {
- PySys_FormatStderr("import sys # builtin\n");
- }
- if (PyDict_SetItemString(sys_modules, "_imp", impmod) < 0) {
+ if (_PyImport_SetModuleString("_imp", impmod) < 0) {
Py_FatalError("Py_Initialize: can't save _imp to sys.modules");
}
@@ -1916,8 +1912,7 @@ wait_for_thread_shutdown(void)
{
_Py_IDENTIFIER(_shutdown);
PyObject *result;
- PyObject *modules = PyImport_GetModuleDict();
- PyObject *threading = PyMapping_GetItemString(modules, "threading");
+ PyObject *threading = _PyImport_GetModuleId(&PyId_threading);
if (threading == NULL) {
/* threading not imported */
PyErr_Clear();