diff options
author | Victor Stinner <vstinner@python.org> | 2019-12-06 02:37:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-06 02:37:07 (GMT) |
commit | d863ade0c7fa4826e8b71aa467809c83a711f019 (patch) | |
tree | 8a213b29df7a82b952a6a741f6265cff66b5b8b2 /Python | |
parent | 81fe5bd3d78f9bb955f8255404d99df27a31c36a (diff) | |
download | cpython-d863ade0c7fa4826e8b71aa467809c83a711f019.zip cpython-d863ade0c7fa4826e8b71aa467809c83a711f019.tar.gz cpython-d863ade0c7fa4826e8b71aa467809c83a711f019.tar.bz2 |
bpo-38858: Add pycore_interp_init() code to factorize code (GH-17483)
Add a new pycore_interp_init() function called by new_interpreter()
and pyinit_config().
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pylifecycle.c | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 9822cce..8bd71a3 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -702,42 +702,51 @@ pycore_init_import_warnings(PyThreadState *tstate, PyObject *sysmod) static PyStatus -pyinit_config(_PyRuntimeState *runtime, - PyThreadState **tstate_p, - const PyConfig *config) +pycore_interp_init(PyThreadState *tstate) { - _PyConfig_Write(config, runtime); + PyStatus status; - PyStatus status = pycore_init_runtime(runtime, config); + status = pycore_init_types(tstate); if (_PyStatus_EXCEPTION(status)) { return status; } - PyThreadState *tstate; - status = pycore_create_interpreter(runtime, config, &tstate); + PyObject *sysmod; + status = _PySys_Create(tstate, &sysmod); if (_PyStatus_EXCEPTION(status)) { return status; } - config = &tstate->interp->config; - *tstate_p = tstate; - status = pycore_init_types(tstate); + status = pycore_init_builtins(tstate); if (_PyStatus_EXCEPTION(status)) { return status; } - PyObject *sysmod; - status = _PySys_Create(tstate, &sysmod); + return pycore_init_import_warnings(tstate, sysmod); +} + + +static PyStatus +pyinit_config(_PyRuntimeState *runtime, + PyThreadState **tstate_p, + const PyConfig *config) +{ + _PyConfig_Write(config, runtime); + + PyStatus status = pycore_init_runtime(runtime, config); if (_PyStatus_EXCEPTION(status)) { return status; } - status = pycore_init_builtins(tstate); + PyThreadState *tstate; + status = pycore_create_interpreter(runtime, config, &tstate); if (_PyStatus_EXCEPTION(status)) { return status; } + config = &tstate->interp->config; + *tstate_p = tstate; - status = pycore_init_import_warnings(tstate, sysmod); + status = pycore_interp_init(tstate); if (_PyStatus_EXCEPTION(status)) { return status; } @@ -1549,25 +1558,8 @@ new_interpreter(PyThreadState **tstate_p) if (_PyStatus_EXCEPTION(status)) { goto error; } - config = &interp->config; - - status = pycore_init_types(tstate); - if (_PyStatus_EXCEPTION(status)) { - goto error; - } - - PyObject *sysmod; - status = _PySys_Create(tstate, &sysmod); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - - status = pycore_init_builtins(tstate); - if (_PyStatus_EXCEPTION(status)) { - goto error; - } - status = pycore_init_import_warnings(tstate, sysmod); + status = pycore_interp_init(tstate); if (_PyStatus_EXCEPTION(status)) { goto error; } |