diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-27 12:40:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-27 12:40:14 (GMT) |
commit | 5ac27a50ff2b42216746fedc0522a92c53089bb3 (patch) | |
tree | 5fbf53a0b5e47f6704f01397de3e01799bf87d41 /Modules | |
parent | 364f0b0f19cc3f0d5e63f571ec9163cf41c62958 (diff) | |
download | cpython-5ac27a50ff2b42216746fedc0522a92c53089bb3.zip cpython-5ac27a50ff2b42216746fedc0522a92c53089bb3.tar.gz cpython-5ac27a50ff2b42216746fedc0522a92c53089bb3.tar.bz2 |
bpo-36444: Rework _Py_InitializeFromConfig() API (GH-12576)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/main.c | 60 |
1 files changed, 19 insertions, 41 deletions
diff --git a/Modules/main.c b/Modules/main.c index 57d1609..ff79edb 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -34,27 +34,7 @@ extern "C" { /* --- pymain_init() ---------------------------------------------- */ static _PyInitError -pymain_init_preconfig(const _PyArgv *args) -{ - _PyInitError err; - - _PyPreConfig config = _PyPreConfig_INIT; - - err = _PyPreConfig_Read(&config, args, NULL); - if (_Py_INIT_FAILED(err)) { - goto done; - } - - err = _Py_PreInitializeInPlace(&config); - -done: - _PyPreConfig_Clear(&config); - return err; -} - - -static _PyInitError -pymain_init(const _PyArgv *args, PyInterpreterState **interp_p) +pymain_init(const _PyArgv *args) { _PyInitError err; @@ -72,28 +52,24 @@ pymain_init(const _PyArgv *args, PyInterpreterState **interp_p) fedisableexcept(FE_OVERFLOW); #endif - err = pymain_init_preconfig(args); - if (_Py_INIT_FAILED(err)) { - return err; - } - _PyCoreConfig config = _PyCoreConfig_INIT; - err = _PyCoreConfig_Read(&config, args); - if (_Py_INIT_FAILED(err)) { - goto done; + if (args->use_bytes_argv) { + err = _Py_PreInitializeFromArgs(NULL, args->argc, args->bytes_argv); + } + else { + err = _Py_PreInitializeFromWideArgs(NULL, args->argc, args->wchar_argv); } - - err = _Py_InitializeFromConfig(&config, interp_p); if (_Py_INIT_FAILED(err)) { - goto done; + return err; } - err = _Py_INIT_OK(); - -done: - _PyCoreConfig_Clear(&config); - return err; + if (args->use_bytes_argv) { + return _Py_InitializeFromArgs(&config, args->argc, args->bytes_argv); + } + else { + return _Py_InitializeFromWideArgs(&config, args->argc, args->wchar_argv); + } } @@ -468,9 +444,12 @@ pymain_repl(_PyCoreConfig *config, PyCompilerFlags *cf, int *exitcode) static _PyInitError -pymain_run_python(PyInterpreterState *interp, int *exitcode) +pymain_run_python(int *exitcode) { _PyInitError err; + + PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE(); + /* pymain_run_stdin() modify the config */ _PyCoreConfig *config = &interp->core_config; PyObject *main_importer_path = NULL; @@ -586,14 +565,13 @@ pymain_main(_PyArgv *args) { _PyInitError err; - PyInterpreterState *interp; - err = pymain_init(args, &interp); + err = pymain_init(args); if (_Py_INIT_FAILED(err)) { goto exit_init_error; } int exitcode = 0; - err = pymain_run_python(interp, &exitcode); + err = pymain_run_python(&exitcode); if (_Py_INIT_FAILED(err)) { goto exit_init_error; } |