diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-11-24 23:01:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-24 23:01:23 (GMT) |
commit | f04ebe2a4d68b194deeb438e9185efdafc10a832 (patch) | |
tree | a6c6eb6febcdedcb094d8409d2f9ef7cc8716a32 /Modules/main.c | |
parent | 46972b7bc385ec2bdc7f567bbd22c9e56ffdf003 (diff) | |
download | cpython-f04ebe2a4d68b194deeb438e9185efdafc10a832.zip cpython-f04ebe2a4d68b194deeb438e9185efdafc10a832.tar.gz cpython-f04ebe2a4d68b194deeb438e9185efdafc10a832.tar.bz2 |
bpo-32030: Add _PyMainInterpreterConfig.program_name (#4548)
* Py_Main() now calls Py_SetProgramName() earlier to be able to get
the program name in _PyMainInterpreterConfig_ReadEnv().
* Rename prog to program_name
* Rename progpath to program_name
Diffstat (limited to 'Modules/main.c')
-rw-r--r-- | Modules/main.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Modules/main.c b/Modules/main.c index 5b0c049..dca165d 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -1452,6 +1452,13 @@ _PyMainInterpreterConfig_ReadEnv(_PyMainInterpreterConfig *config) return err; } + /* FIXME: _PyMainInterpreterConfig_Read() has the same code. Remove it + here? See also pymain_get_program_name() and pymain_parse_envvars(). */ + config->program_name = _PyMem_RawWcsdup(Py_GetProgramName()); + if (config->program_name == NULL) { + return _Py_INIT_NO_MEMORY(); + } + return _Py_INIT_OK(); } @@ -1480,6 +1487,15 @@ pymain_parse_envvars(_PyMain *pymain) } core_config->allocator = Py_GETENV("PYTHONMALLOC"); + /* FIXME: move pymain_get_program_name() code into + _PyMainInterpreterConfig_ReadEnv(). + Problem: _PyMainInterpreterConfig_ReadEnv() doesn't have access + to argv[0]. */ + Py_SetProgramName(pymain->program_name); + /* Don't free program_name here: the argument to Py_SetProgramName + must remain valid until Py_FinalizeEx is called. The string is freed + by pymain_free(). */ + _PyInitError err = _PyMainInterpreterConfig_ReadEnv(&pymain->config); if (_Py_INIT_FAILED(pymain->err)) { pymain->err = err; @@ -1569,11 +1585,6 @@ pymain_init_python(_PyMain *pymain) return -1; } - Py_SetProgramName(pymain->program_name); - /* Don't free program_name here: the argument to Py_SetProgramName - must remain valid until Py_FinalizeEx is called. The string is freed - by pymain_free(). */ - if (pymain_add_xoptions(pymain)) { return -1; } |