Commit 95e2cbf3 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-36142: Move command line parsing to coreconfig.c (GH-12123)

* Add _PyCoreConfig_ReadFromArgv() function which parses command line
  options: move code from main.c to coreconfig.c.
* Add _PyCoreConfig_Write() to write the new configuration: coerce
  the LC_CTYPE locale, set Py_xxx global configuration variables,
  etc.
* _PyCoreConfig_ReadFromArgv() now only changes the LC_CTYPE locale
  temporarily. _PyCoreConfig_Write() becomes responsible to set the
  LC_CTYPE locale.
* Add _Py_SetArgcArgv() and _Py_ClearArgcArgv() functions
* Rename many "pymain_xxx()" functions
* Add "const" to some function parameters
* Reorganize main.c to declare functions in the order in which they
  are called.
parent 625dbf25
...@@ -5,6 +5,16 @@ ...@@ -5,6 +5,16 @@
extern "C" { extern "C" {
#endif #endif
/* _PyArgv */
typedef struct {
int argc;
int use_bytes_argv;
char **bytes_argv;
wchar_t **wchar_argv;
} _PyArgv;
/* _PyInitError */ /* _PyInitError */
typedef struct { typedef struct {
......
...@@ -8,6 +8,29 @@ extern "C" { ...@@ -8,6 +8,29 @@ extern "C" {
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined" # error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
#endif #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);
/* Py_GetArgcArgv() helpers */
PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
PyAPI_FUNC(int) _Py_SetArgcArgv(int argc, wchar_t * const *argv);
/* _PyCoreConfig */
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config); PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config);
PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *); PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *);
PyAPI_FUNC(int) _PyCoreConfig_Copy( PyAPI_FUNC(int) _PyCoreConfig_Copy(
...@@ -26,6 +49,9 @@ PyAPI_FUNC(int) _PyCoreConfig_GetEnvDup( ...@@ -26,6 +49,9 @@ PyAPI_FUNC(int) _PyCoreConfig_GetEnvDup(
wchar_t **dest, wchar_t **dest,
wchar_t *wname, wchar_t *wname,
char *name); char *name);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config,
const _PyArgv *args);
PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -8,20 +8,6 @@ extern "C" { ...@@ -8,20 +8,6 @@ extern "C" {
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define" # error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
#endif #endif
PyAPI_FUNC(void) _Py_wstrlist_clear(
int len,
wchar_t **list);
PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
int len,
wchar_t **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);
typedef struct _PyPathConfig { typedef struct _PyPathConfig {
/* Full path to the Python program */ /* Full path to the Python program */
wchar_t *program_full_path; wchar_t *program_full_path;
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment