]> granicus.if.org Git - python/commitdiff
bpo-36763: Add _PyCoreConfig_SetArgv() (GH-13030)
authorVictor Stinner <vstinner@redhat.com>
Wed, 1 May 2019 00:30:12 +0000 (02:30 +0200)
committerGitHub <noreply@github.com>
Wed, 1 May 2019 00:30:12 +0000 (02:30 +0200)
* Add 2 new config methods:

  * _PyCoreConfig_SetArgv()
  * _PyCoreConfig_SetWideArgv()

* Add also an internal _PyCoreConfig_SetPyArgv() method.
* Remove 'args' parameter from _PyCoreConfig_Read().

Include/internal/pycore_coreconfig.h
Lib/test/pythoninfo.py
Python/coreconfig.c
Python/pathconfig.c
Python/pylifecycle.c

index ac98e00159ce3be4978340fc7141eecaa8969681..b1d02eef4513d3edeb5be364887aaa44ca8594fe 100644 (file)
@@ -108,11 +108,21 @@ PyAPI_FUNC(int) _PyCoreConfig_Copy(
 PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig(_PyCoreConfig *config);
 PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPathConfig(
     const _PyCoreConfig *config);
-PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config,
-    const _PyArgv *args);
+PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config);
 PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config,
     _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 ---------------------------------- */
 
index 580956633f4d40e57964fac40b5d8dd4c63b703c..e9edf675b9105af05e31810c2369ae6dbf61eff1 100644 (file)
@@ -602,8 +602,7 @@ def collect_gdbm(info_add):
 
 
 def collect_get_config(info_add):
-    # Dump global configuration variables, _PyCoreConfig
-    # and _PyMainInterpreterConfig
+    # Get global configuration variables, _PyPreConfig and _PyCoreConfig
     try:
         from _testinternalcapi import get_configs
     except ImportError:
index 471d5126f8038d47ab2ed29f6107db50d9b7fdd4..750676a4731c457143b31ad89f9ea3ab604d94fc 100644 (file)
@@ -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;
     }
index 10e141a47de02b495026929464edaa1a6763cdbe..7fea7c3667865c45e6488b630824cbd0b46d8dcc 100644 (file)
@@ -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;
     }
index d93fe065558aa39bbc499c16363114631342922f..185d4066e50b1c11697004e2eecfc11251203f0f 100644 (file)
@@ -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;
     }