summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-03-15 14:08:05 (GMT)
committerGitHub <noreply@github.com>2019-03-15 14:08:05 (GMT)
commit74f6568bbd3e70806ea3219e8bacb386ad802ccf (patch)
tree98516f3e71020f12109372492180a835307e129f /Modules/main.c
parent86082c22d23285995a32aabb491527c9f5629556 (diff)
downloadcpython-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 'Modules/main.c')
-rw-r--r--Modules/main.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/Modules/main.c b/Modules/main.c
index ae99901..5c7f7e4 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -84,15 +84,15 @@ error:
static PyObject*
mainconfig_create_xoptions_dict(const _PyCoreConfig *config)
{
- int nxoption = config->nxoption;
- wchar_t **xoptions = config->xoptions;
+ Py_ssize_t nxoption = config->xoptions.length;
+ wchar_t * const * xoptions = config->xoptions.items;
PyObject *dict = PyDict_New();
if (dict == NULL) {
return NULL;
}
- for (int i=0; i < nxoption; i++) {
- wchar_t *option = xoptions[i];
+ for (Py_ssize_t i=0; i < nxoption; i++) {
+ const wchar_t *option = xoptions[i];
if (mainconfig_add_xoption(dict, option) < 0) {
Py_DECREF(dict);
return NULL;
@@ -243,22 +243,18 @@ _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *main_config,
} \
} \
} while (0)
-#define COPY_WSTRLIST(ATTR, LEN, LIST) \
+#define COPY_WSTRLIST(ATTR, LIST) \
do { \
if (ATTR == NULL) { \
- ATTR = _Py_wstrlist_as_pylist(LEN, LIST); \
+ ATTR = _PyWstrList_AsList(LIST); \
if (ATTR == NULL) { \
return _Py_INIT_NO_MEMORY(); \
} \
} \
} while (0)
- COPY_WSTRLIST(main_config->warnoptions,
- config->nwarnoption, config->warnoptions);
- if (config->argc >= 0) {
- COPY_WSTRLIST(main_config->argv,
- config->argc, config->argv);
- }
+ COPY_WSTRLIST(main_config->warnoptions, &config->warnoptions);
+ COPY_WSTRLIST(main_config->argv, &config->argv);
if (config->_install_importlib) {
COPY_WSTR(executable);
@@ -268,7 +264,7 @@ _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *main_config,
COPY_WSTR(base_exec_prefix);
COPY_WSTRLIST(main_config->module_search_path,
- config->nmodule_search_path, config->module_search_paths);
+ &config->module_search_paths);
if (config->pycache_prefix != NULL) {
COPY_WSTR(pycache_prefix);
@@ -784,8 +780,7 @@ pymain_run_python(PyInterpreterState *interp, int *exitcode)
}
}
else if (!config->preconfig.isolated) {
- PyObject *path0 = _PyPathConfig_ComputeArgv0(config->argc,
- config->argv);
+ PyObject *path0 = _PyPathConfig_ComputeArgv0(&config->argv);
if (path0 == NULL) {
err = _Py_INIT_NO_MEMORY();
goto done;