mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-36763: Add _PyCoreConfig_SetArgv() (GH-13030)
* Add 2 new config methods: * _PyCoreConfig_SetArgv() * _PyCoreConfig_SetWideArgv() * Add also an internal _PyCoreConfig_SetPyArgv() method. * Remove 'args' parameter from _PyCoreConfig_Read().
This commit is contained in:
parent
463b82a3ef
commit
5f38b8407b
5 changed files with 58 additions and 17 deletions
|
@ -2003,8 +2003,7 @@ config_init_argv(_PyCoreConfig *config, const _PyPreCmdline *cmdline)
|
|||
|
||||
|
||||
static _PyInitError
|
||||
core_read_precmdline(_PyCoreConfig *config, const _PyArgv *args,
|
||||
_PyPreCmdline *precmdline)
|
||||
core_read_precmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline)
|
||||
{
|
||||
_PyInitError err;
|
||||
|
||||
|
@ -2072,23 +2071,47 @@ done:
|
|||
}
|
||||
|
||||
|
||||
_PyInitError
|
||||
_PyCoreConfig_SetPyArgv(_PyCoreConfig *config, const _PyArgv *args)
|
||||
{
|
||||
return _PyArgv_AsWstrList(args, &config->argv);
|
||||
}
|
||||
|
||||
|
||||
_PyInitError
|
||||
_PyCoreConfig_SetArgv(_PyCoreConfig *config, int argc, char **argv)
|
||||
{
|
||||
_PyArgv args = {
|
||||
.argc = argc,
|
||||
.use_bytes_argv = 1,
|
||||
.bytes_argv = argv,
|
||||
.wchar_argv = NULL};
|
||||
return _PyCoreConfig_SetPyArgv(config, &args);
|
||||
}
|
||||
|
||||
|
||||
_PyInitError
|
||||
_PyCoreConfig_SetWideArgv(_PyCoreConfig *config, int argc, wchar_t **argv)
|
||||
{
|
||||
_PyArgv args = {
|
||||
.argc = argc,
|
||||
.use_bytes_argv = 0,
|
||||
.bytes_argv = NULL,
|
||||
.wchar_argv = argv};
|
||||
return _PyCoreConfig_SetPyArgv(config, &args);
|
||||
}
|
||||
|
||||
|
||||
/* Read the configuration into _PyCoreConfig from:
|
||||
|
||||
* Command line arguments
|
||||
* Environment variables
|
||||
* Py_xxx global configuration variables */
|
||||
_PyInitError
|
||||
_PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args)
|
||||
_PyCoreConfig_Read(_PyCoreConfig *config)
|
||||
{
|
||||
_PyInitError err;
|
||||
|
||||
if (args) {
|
||||
err = _PyArgv_AsWstrList(args, &config->argv);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
err = _Py_PreInitializeFromCoreConfig(config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
|
@ -2097,7 +2120,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args)
|
|||
_PyCoreConfig_GetGlobalConfig(config);
|
||||
|
||||
_PyPreCmdline precmdline = _PyPreCmdline_INIT;
|
||||
err = core_read_precmdline(config, args, &precmdline);
|
||||
err = core_read_precmdline(config, &precmdline);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
goto done;
|
||||
}
|
||||
|
|
|
@ -394,7 +394,7 @@ pathconfig_global_init(void)
|
|||
_PyInitError err;
|
||||
_PyCoreConfig config = _PyCoreConfig_INIT;
|
||||
|
||||
err = _PyCoreConfig_Read(&config, NULL);
|
||||
err = _PyCoreConfig_Read(&config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
goto error;
|
||||
}
|
||||
|
|
|
@ -801,13 +801,22 @@ pyinit_coreconfig(_PyRuntimeState *runtime,
|
|||
const _PyArgv *args,
|
||||
PyInterpreterState **interp_p)
|
||||
{
|
||||
_PyInitError err;
|
||||
|
||||
if (src_config) {
|
||||
if (_PyCoreConfig_Copy(config, src_config) < 0) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
}
|
||||
}
|
||||
|
||||
_PyInitError err = _PyCoreConfig_Read(config, args);
|
||||
if (args) {
|
||||
err = _PyCoreConfig_SetPyArgv(config, args);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
err = _PyCoreConfig_Read(config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue