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.
This commit is contained in:
Victor Stinner 2019-03-01 16:25:19 +01:00 committed by GitHub
parent 625dbf2567
commit 95e2cbf32f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1523 additions and 1465 deletions

View File

@ -5,6 +5,16 @@
extern "C" {
#endif
/* _PyArgv */
typedef struct {
int argc;
int use_bytes_argv;
char **bytes_argv;
wchar_t **wchar_argv;
} _PyArgv;
/* _PyInitError */
typedef struct {

View File

@ -8,6 +8,29 @@ 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);
/* 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(void) _PyCoreConfig_Clear(_PyCoreConfig *);
PyAPI_FUNC(int) _PyCoreConfig_Copy(
@ -26,6 +49,9 @@ PyAPI_FUNC(int) _PyCoreConfig_GetEnvDup(
wchar_t **dest,
wchar_t *wname,
char *name);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config,
const _PyArgv *args);
PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config);
#ifdef __cplusplus
}

View File

@ -8,20 +8,6 @@ extern "C" {
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
#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 {
/* Full path to the Python program */
wchar_t *program_full_path;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff