Commit 5f38b840 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

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().
parent 463b82a3
...@@ -108,11 +108,21 @@ PyAPI_FUNC(int) _PyCoreConfig_Copy( ...@@ -108,11 +108,21 @@ PyAPI_FUNC(int) _PyCoreConfig_Copy(
PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig(_PyCoreConfig *config); PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig(_PyCoreConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPathConfig( PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPathConfig(
const _PyCoreConfig *config); const _PyCoreConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config, PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config);
const _PyArgv *args);
PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config, PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config,
_PyRuntimeState *runtime); _PyRuntimeState *runtime);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPyArgv(
_PyCoreConfig *config,
const _PyArgv *args);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetArgv(
_PyCoreConfig *config,
int argc,
char **argv);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetWideArgv(_PyCoreConfig *config,
int argc,
wchar_t **argv);
/* --- Function used for testing ---------------------------------- */ /* --- Function used for testing ---------------------------------- */
......
...@@ -602,8 +602,7 @@ def collect_gdbm(info_add): ...@@ -602,8 +602,7 @@ def collect_gdbm(info_add):
def collect_get_config(info_add): def collect_get_config(info_add):
# Dump global configuration variables, _PyCoreConfig # Get global configuration variables, _PyPreConfig and _PyCoreConfig
# and _PyMainInterpreterConfig
try: try:
from _testinternalcapi import get_configs from _testinternalcapi import get_configs
except ImportError: except ImportError:
......
...@@ -2003,8 +2003,7 @@ config_init_argv(_PyCoreConfig *config, const _PyPreCmdline *cmdline) ...@@ -2003,8 +2003,7 @@ config_init_argv(_PyCoreConfig *config, const _PyPreCmdline *cmdline)
static _PyInitError static _PyInitError
core_read_precmdline(_PyCoreConfig *config, const _PyArgv *args, core_read_precmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline)
_PyPreCmdline *precmdline)
{ {
_PyInitError err; _PyInitError err;
...@@ -2072,23 +2071,47 @@ done: ...@@ -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: /* Read the configuration into _PyCoreConfig from:
* Command line arguments * Command line arguments
* Environment variables * Environment variables
* Py_xxx global configuration variables */ * Py_xxx global configuration variables */
_PyInitError _PyInitError
_PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) _PyCoreConfig_Read(_PyCoreConfig *config)
{ {
_PyInitError err; _PyInitError err;
if (args) {
err = _PyArgv_AsWstrList(args, &config->argv);
if (_Py_INIT_FAILED(err)) {
return err;
}
}
err = _Py_PreInitializeFromCoreConfig(config); err = _Py_PreInitializeFromCoreConfig(config);
if (_Py_INIT_FAILED(err)) { if (_Py_INIT_FAILED(err)) {
return err; return err;
...@@ -2097,7 +2120,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args) ...@@ -2097,7 +2120,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyArgv *args)
_PyCoreConfig_GetGlobalConfig(config); _PyCoreConfig_GetGlobalConfig(config);
_PyPreCmdline precmdline = _PyPreCmdline_INIT; _PyPreCmdline precmdline = _PyPreCmdline_INIT;
err = core_read_precmdline(config, args, &precmdline); err = core_read_precmdline(config, &precmdline);
if (_Py_INIT_FAILED(err)) { if (_Py_INIT_FAILED(err)) {
goto done; goto done;
} }
......
...@@ -394,7 +394,7 @@ pathconfig_global_init(void) ...@@ -394,7 +394,7 @@ pathconfig_global_init(void)
_PyInitError err; _PyInitError err;
_PyCoreConfig config = _PyCoreConfig_INIT; _PyCoreConfig config = _PyCoreConfig_INIT;
err = _PyCoreConfig_Read(&config, NULL); err = _PyCoreConfig_Read(&config);
if (_Py_INIT_FAILED(err)) { if (_Py_INIT_FAILED(err)) {
goto error; goto error;
} }
......
...@@ -801,13 +801,22 @@ pyinit_coreconfig(_PyRuntimeState *runtime, ...@@ -801,13 +801,22 @@ pyinit_coreconfig(_PyRuntimeState *runtime,
const _PyArgv *args, const _PyArgv *args,
PyInterpreterState **interp_p) PyInterpreterState **interp_p)
{ {
_PyInitError err;
if (src_config) { if (src_config) {
if (_PyCoreConfig_Copy(config, src_config) < 0) { if (_PyCoreConfig_Copy(config, src_config) < 0) {
return _Py_INIT_NO_MEMORY(); 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)) { if (_Py_INIT_FAILED(err)) {
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment