diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-12-13 16:31:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-13 16:31:16 (GMT) |
commit | d5dda98fa80405db82e2eb36ac48671b4c8c0983 (patch) | |
tree | ddece44d8035bccea47121caf6c55932ba44301e /Python | |
parent | 981469794af8c693174544265b0c19cbe6d2b457 (diff) | |
download | cpython-d5dda98fa80405db82e2eb36ac48671b4c8c0983.zip cpython-d5dda98fa80405db82e2eb36ac48671b4c8c0983.tar.gz cpython-d5dda98fa80405db82e2eb36ac48671b4c8c0983.tar.bz2 |
pymain_set_sys_argv() now copies argv (#4838)
bpo-29240, bpo-32030:
* Rename pymain_set_argv() to pymain_set_sys_argv()
* pymain_set_sys_argv() now creates of copy of argv and modify the
copy, rather than modifying pymain->argv
* Call pymain_set_sys_argv() earlier: before pymain_run_python(), but
after pymain_get_importer().
* Add _PySys_SetArgvWithError() to handle errors
Diffstat (limited to 'Python')
-rw-r--r-- | Python/sysmodule.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 141e189..ea2ccb2 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2446,17 +2446,34 @@ sys_update_path(int argc, wchar_t **argv) Py_DECREF(a); } -void -PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) +_PyInitError +_PySys_SetArgvWithError(int argc, wchar_t **argv, int updatepath) { PyObject *av = makeargvobject(argc, argv); - if (av == NULL) - Py_FatalError("no mem for sys.argv"); - if (PySys_SetObject("argv", av) != 0) - Py_FatalError("can't assign sys.argv"); + if (av == NULL) { + return _Py_INIT_NO_MEMORY(); + } + if (PySys_SetObject("argv", av) != 0) { + Py_DECREF(av); + return _Py_INIT_ERR("can't assign sys.argv"); + } Py_DECREF(av); - if (updatepath) + + if (updatepath) { + /* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path. + If argv[0] is a symlink, use the real path. */ sys_update_path(argc, argv); + } + return _Py_INIT_OK(); +} + +void +PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) +{ + _PyInitError err = _PySys_SetArgvWithError(argc, argv, updatepath); + if (_Py_INIT_FAILED(err)) { + _Py_FatalInitError(err); + } } void |