summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-16 15:02:56 (GMT)
committerGitHub <noreply@github.com>2019-05-16 15:02:56 (GMT)
commitae239f6b0626e926613a4a1dbafa323bd41fec32 (patch)
treec811687161a90a5a03dc29b83774b5f9688579d7 /Include
parent68b34a720485f399e8699235b8f4e08f227dd43b (diff)
downloadcpython-ae239f6b0626e926613a4a1dbafa323bd41fec32.zip
cpython-ae239f6b0626e926613a4a1dbafa323bd41fec32.tar.gz
cpython-ae239f6b0626e926613a4a1dbafa323bd41fec32.tar.bz2
bpo-36763: Add _PyCoreConfig.parse_argv (GH-13361)
* _PyCoreConfig_Read() doesn't parse nor update argv if parse_argv is 0. * Move path configuration fields in _PyCoreConfig. * Add an unit test for parse_argv=0. * Remove unused "done": label in _Py_RunMain().
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/coreconfig.h61
1 files changed, 39 insertions, 22 deletions
diff --git a/Include/cpython/coreconfig.h b/Include/cpython/coreconfig.h
index f9bde14..a04342e 100644
--- a/Include/cpython/coreconfig.h
+++ b/Include/cpython/coreconfig.h
@@ -207,31 +207,25 @@ typedef struct {
wchar_t *filesystem_errors;
wchar_t *pycache_prefix; /* PYTHONPYCACHEPREFIX, -X pycache_prefix=PATH */
- wchar_t *program_name; /* Program name, see also Py_GetProgramName() */
- _PyWstrList argv; /* Command line arguments */
- wchar_t *program; /* argv[0] or "" */
- _PyWstrList xoptions; /* Command line -X options */
- _PyWstrList warnoptions; /* Warnings options */
+ int parse_argv; /* Parse argv command line arguments? */
- /* Path configuration inputs */
- wchar_t *module_search_path_env; /* PYTHONPATH environment variable */
- wchar_t *home; /* PYTHONHOME environment variable,
- see also Py_SetPythonHome(). */
+ /* Command line arguments (sys.argv).
- /* Path configuration outputs */
- int use_module_search_paths; /* If non-zero, use module_search_paths */
- _PyWstrList module_search_paths; /* sys.path paths. Computed if
- use_module_search_paths is equal
- to zero. */
+ By default, Python command line arguments are parsed and then stripped
+ from argv. Set parse_argv to 0 to avoid that.
- wchar_t *executable; /* sys.executable */
- wchar_t *prefix; /* sys.prefix */
- wchar_t *base_prefix; /* sys.base_prefix */
- wchar_t *exec_prefix; /* sys.exec_prefix */
- wchar_t *base_exec_prefix; /* sys.base_exec_prefix */
-#ifdef MS_WINDOWS
- wchar_t *dll_path; /* Windows DLL path */
-#endif
+ If argv is empty, an empty string is added to ensure that sys.argv
+ always exists and is never empty. */
+ _PyWstrList argv;
+
+ /* Program: argv[0] or "".
+ Used to display Python usage if parsing command line arguments fails.
+ Used to initialize the default value of program_name */
+ wchar_t *program;
+ wchar_t *program_name; /* Program name, see also Py_GetProgramName() */
+
+ _PyWstrList xoptions; /* Command line -X options */
+ _PyWstrList warnoptions; /* Warnings options */
/* If equal to zero, disable the import of the module site and the
site-dependent manipulations of sys.path that it entails. Also disable
@@ -350,6 +344,28 @@ typedef struct {
int legacy_windows_stdio;
#endif
+ /* --- Path configuration inputs ------------ */
+
+ wchar_t *module_search_path_env; /* PYTHONPATH environment variable */
+ wchar_t *home; /* PYTHONHOME environment variable,
+ see also Py_SetPythonHome(). */
+
+ /* --- Path configuration outputs ----------- */
+
+ int use_module_search_paths; /* If non-zero, use module_search_paths */
+ _PyWstrList module_search_paths; /* sys.path paths. Computed if
+ use_module_search_paths is equal
+ to zero. */
+
+ wchar_t *executable; /* sys.executable */
+ wchar_t *prefix; /* sys.prefix */
+ wchar_t *base_prefix; /* sys.base_prefix */
+ wchar_t *exec_prefix; /* sys.exec_prefix */
+ wchar_t *base_exec_prefix; /* sys.base_exec_prefix */
+#ifdef MS_WINDOWS
+ wchar_t *dll_path; /* Windows DLL path */
+#endif
+
/* --- Parameter only used by Py_Main() ---------- */
/* Skip the first line of the source ('run_filename' parameter), allowing use of non-Unix forms of
@@ -408,6 +424,7 @@ typedef struct {
.faulthandler = -1, \
.tracemalloc = -1, \
.use_module_search_paths = 0, \
+ .parse_argv = 1, \
.site_import = -1, \
.bytes_warning = -1, \
.inspect = -1, \