summaryrefslogtreecommitdiffstats
path: root/Include/internal
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 /Include/internal
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 'Include/internal')
-rw-r--r--Include/internal/pycore_coreconfig.h37
-rw-r--r--Include/internal/pycore_getopt.h6
-rw-r--r--Include/internal/pycore_pathconfig.h2
3 files changed, 22 insertions, 23 deletions
diff --git a/Include/internal/pycore_coreconfig.h b/Include/internal/pycore_coreconfig.h
index 153309d..8c5a072 100644
--- a/Include/internal/pycore_coreconfig.h
+++ b/Include/internal/pycore_coreconfig.h
@@ -8,39 +8,38 @@ extern "C" {
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
#endif
-/* --- _Py_wstrlist ----------------------------------------------- */
-
-PyAPI_FUNC(void) _Py_wstrlist_clear(
- int len,
- wchar_t **list);
-PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
- int len,
- wchar_t * const *list);
-PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
- int *len,
- wchar_t ***list,
- const wchar_t *str);
-PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(
- int len,
- wchar_t **list);
+
+/* --- _PyWstrList ------------------------------------------------ */
+
+#ifndef NDEBUG
+PyAPI_FUNC(int) _PyWstrList_CheckConsistency(const _PyWstrList *list);
+#endif
+PyAPI_FUNC(void) _PyWstrList_Clear(_PyWstrList *list);
+PyAPI_FUNC(int) _PyWstrList_Copy(_PyWstrList *list,
+ const _PyWstrList *list2);
+PyAPI_FUNC(int) _PyWstrList_Append(_PyWstrList *list,
+ const wchar_t *item);
+PyAPI_FUNC(PyObject*) _PyWstrList_AsList(const _PyWstrList *list);
+
/* --- _PyArgv ---------------------------------------------------- */
-PyAPI_FUNC(_PyInitError) _PyArgv_Decode(const _PyArgv *args,
- wchar_t*** argv_p);
+PyAPI_FUNC(_PyInitError) _PyArgv_AsWstrList(const _PyArgv *args,
+ _PyWstrList *list);
+
/* --- Py_GetArgcArgv() helpers ----------------------------------- */
PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
+
/* --- _PyPreConfig ----------------------------------------------- */
PyAPI_FUNC(int) _Py_str_to_int(
const char *str,
int *result);
PyAPI_FUNC(const wchar_t*) _Py_get_xoption(
- int nxoption,
- wchar_t * const *xoptions,
+ const _PyWstrList *xoptions,
const wchar_t *name);
PyAPI_FUNC(void) _PyPreConfig_Clear(_PyPreConfig *config);
diff --git a/Include/internal/pycore_getopt.h b/Include/internal/pycore_getopt.h
index 1d30f5b..0d1897c 100644
--- a/Include/internal/pycore_getopt.h
+++ b/Include/internal/pycore_getopt.h
@@ -6,8 +6,8 @@
#endif
extern int _PyOS_opterr;
-extern int _PyOS_optind;
-extern wchar_t *_PyOS_optarg;
+extern Py_ssize_t _PyOS_optind;
+extern const wchar_t *_PyOS_optarg;
extern void _PyOS_ResetGetOpt(void);
@@ -17,6 +17,6 @@ typedef struct {
int val;
} _PyOS_LongOption;
-extern int _PyOS_GetOpt(int argc, wchar_t **argv, int *longindex);
+extern int _PyOS_GetOpt(Py_ssize_t argc, wchar_t **argv, int *longindex);
#endif /* !Py_INTERNAL_PYGETOPT_H */
diff --git a/Include/internal/pycore_pathconfig.h b/Include/internal/pycore_pathconfig.h
index fb6b1d7..d0938df 100644
--- a/Include/internal/pycore_pathconfig.h
+++ b/Include/internal/pycore_pathconfig.h
@@ -44,7 +44,7 @@ PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
_PyPathConfig *config,
const _PyCoreConfig *core_config);
-PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
+PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(const _PyWstrList *argv);
PyAPI_FUNC(int) _Py_FindEnvConfigValue(
FILE *env_file,
const wchar_t *key,