diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-15 14:08:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-15 14:08:05 (GMT) |
commit | 74f6568bbd3e70806ea3219e8bacb386ad802ccf (patch) | |
tree | 98516f3e71020f12109372492180a835307e129f /Include/cpython/coreconfig.h | |
parent | 86082c22d23285995a32aabb491527c9f5629556 (diff) | |
download | cpython-74f6568bbd3e70806ea3219e8bacb386ad802ccf.zip cpython-74f6568bbd3e70806ea3219e8bacb386ad802ccf.tar.gz cpython-74f6568bbd3e70806ea3219e8bacb386ad802ccf.tar.bz2 |
bpo-36301: Add _PyWstrList structure (GH-12343)
Replace messy _Py_wstrlist_xxx() functions with a new clean
_PyWstrList structure and new _PyWstrList_xxx() functions.
Changes:
* Add _PyCoreConfig.use_module_search_paths to decide if
_PyCoreConfig.module_search_paths should be computed or not, to
support empty search path list.
* _PyWstrList_Clear() sets length to 0 and items to NULL, whereas
_Py_wstrlist_clear() only freed memory.
* _PyWstrList_Append() returns an int, whereas _Py_wstrlist_append()
returned _PyInitError.
* _PyWstrList uses Py_ssize_t for the length, instead of int.
* Replace (int, wchar_t**) with _PyWstrList in:
* _PyPreConfig
* _PyCoreConfig
* _PyPreCmdline
* _PyCmdline
* Replace "int orig_argv; wchar_t **orig_argv;"
with "_PyWstrList orig_argv".
* _PyCmdline and _PyPreCmdline now also copy wchar_argv.
* Rename _PyArgv_Decode() to _PyArgv_AsWstrList().
* PySys_SetArgvEx() now pass the fixed (argc, argv) to
_PyPathConfig_ComputeArgv0() (don't pass negative argc or NULL
argv).
* _PyOS_GetOpt() uses Py_ssize_t
Diffstat (limited to 'Include/cpython/coreconfig.h')
-rw-r--r-- | Include/cpython/coreconfig.h | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/Include/cpython/coreconfig.h b/Include/cpython/coreconfig.h index 2673576..bd28c37 100644 --- a/Include/cpython/coreconfig.h +++ b/Include/cpython/coreconfig.h @@ -46,6 +46,18 @@ typedef struct { #define _Py_INIT_FAILED(err) \ (err.msg != NULL || err.exitcode != -1) +/* --- _PyWstrList ------------------------------------------------ */ + +typedef struct { + /* If length is greater than zero, items must be non-NULL + and all items strings must be non-NULL */ + Py_ssize_t length; + wchar_t **items; +} _PyWstrList; + +#define _PyWstrList_INIT (_PyWstrList){.length = 0, .items = NULL} + + /* --- _PyPreConfig ----------------------------------------------- */ typedef struct { @@ -162,19 +174,12 @@ typedef struct { char *filesystem_encoding; char *filesystem_errors; - wchar_t *pycache_prefix; /* PYTHONPYCACHEPREFIX, -X pycache_prefix=PATH */ - - wchar_t *program_name; /* Program name, see also Py_GetProgramName() */ - int argc; /* Number of command line arguments, - -1 means unset */ - wchar_t **argv; /* Command line arguments */ - wchar_t *program; /* argv[0] or "" */ - - int nxoption; /* Number of -X options */ - wchar_t **xoptions; /* -X options */ - - int nwarnoption; /* Number of warnings options */ - wchar_t **warnoptions; /* Warnings options */ + 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 */ /* Path configuration inputs */ wchar_t *module_search_path_env; /* PYTHONPATH environment variable */ @@ -182,9 +187,11 @@ typedef struct { see also Py_SetPythonHome(). */ /* Path configuration outputs */ - int nmodule_search_path; /* Number of sys.path paths, - -1 means unset */ - wchar_t **module_search_paths; /* sys.path paths */ + 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 */ @@ -366,8 +373,7 @@ typedef struct { .use_hash_seed = -1, \ .faulthandler = -1, \ .tracemalloc = -1, \ - .argc = -1, \ - .nmodule_search_path = -1, \ + .use_module_search_paths = 0, \ .site_import = -1, \ .bytes_warning = -1, \ .inspect = -1, \ |