diff options
author | Victor Stinner <vstinner@python.org> | 2019-12-06 01:43:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-06 01:43:30 (GMT) |
commit | 81fe5bd3d78f9bb955f8255404d99df27a31c36a (patch) | |
tree | 84cea2b30986366a4c2f5a23b3d9858deb078f29 /Python/sysmodule.c | |
parent | 44ea525ca56ad8ef783cbcd3a0636a425e5d801a (diff) | |
download | cpython-81fe5bd3d78f9bb955f8255404d99df27a31c36a.zip cpython-81fe5bd3d78f9bb955f8255404d99df27a31c36a.tar.gz cpython-81fe5bd3d78f9bb955f8255404d99df27a31c36a.tar.bz2 |
bpo-38858: new_interpreter() reuses _PySys_Create() (GH-17481)
new_interpreter() now calls _PySys_Create() to create a new sys
module isolated from the main interpreter. It now calls
_PySys_InitCore() and _PyImport_FixupBuiltin().
init_interp_main() now calls _PySys_InitMain().
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 78b9d22..b6bdf51 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2919,7 +2919,7 @@ err_occurred: infrastructure for the io module in place. Use UTF-8/surrogateescape and ignore EAGAIN errors. */ -PyStatus +static PyStatus _PySys_SetPreliminaryStderr(PyObject *sysdict) { PyObject *pstderr = PyFile_NewStdPrinter(fileno(stderr)); @@ -2946,11 +2946,13 @@ error: PyStatus _PySys_Create(PyThreadState *tstate, PyObject **sysmod_p) { + assert(!_PyErr_Occurred(tstate)); + PyInterpreterState *interp = tstate->interp; PyObject *modules = PyDict_New(); if (modules == NULL) { - return _PyStatus_ERR("can't make modules dictionary"); + goto error; } interp->modules = modules; @@ -2961,13 +2963,13 @@ _PySys_Create(PyThreadState *tstate, PyObject **sysmod_p) PyObject *sysdict = PyModule_GetDict(sysmod); if (sysdict == NULL) { - return _PyStatus_ERR("can't initialize sys dict"); + goto error; } Py_INCREF(sysdict); interp->sysdict = sysdict; if (PyDict_SetItemString(sysdict, "modules", interp->modules) < 0) { - return _PyStatus_ERR("can't initialize sys module"); + goto error; } PyStatus status = _PySys_SetPreliminaryStderr(sysdict); @@ -2980,10 +2982,17 @@ _PySys_Create(PyThreadState *tstate, PyObject **sysmod_p) return status; } - _PyImport_FixupBuiltin(sysmod, "sys", interp->modules); + if (_PyImport_FixupBuiltin(sysmod, "sys", interp->modules) < 0) { + goto error; + } + + assert(!_PyErr_Occurred(tstate)); *sysmod_p = sysmod; return _PyStatus_OK(); + +error: + return _PyStatus_ERR("can't initialize sys module"); } |