Skip to content

Commit 95e2cbf

Browse files
authored
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.
1 parent 625dbf2 commit 95e2cbf

File tree

5 files changed

+1500
-1442
lines changed

5 files changed

+1500
-1442
lines changed

‎Include/cpython/coreconfig.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
extern "C" {
66
#endif
77

8+
/* _PyArgv */
9+
10+
typedef struct {
11+
int argc;
12+
int use_bytes_argv;
13+
char **bytes_argv;
14+
wchar_t **wchar_argv;
15+
} _PyArgv;
16+
17+
818
/* _PyInitError */
919

1020
typedef struct {

‎Include/internal/pycore_coreconfig.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
99
#endif
1010

11+
/* _Py_wstrlist */
12+
13+
PyAPI_FUNC(void) _Py_wstrlist_clear(
14+
int len,
15+
wchar_t **list);
16+
PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
17+
int len,
18+
wchar_t * const *list);
19+
PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
20+
int *len,
21+
wchar_t ***list,
22+
const wchar_t *str);
23+
PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(
24+
int len,
25+
wchar_t **list);
26+
27+
/* Py_GetArgcArgv() helpers */
28+
29+
PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
30+
PyAPI_FUNC(int) _Py_SetArgcArgv(int argc, wchar_t * const *argv);
31+
32+
/* _PyCoreConfig */
33+
1134
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config);
1235
PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *);
1336
PyAPI_FUNC(int) _PyCoreConfig_Copy(
@@ -26,6 +49,9 @@ PyAPI_FUNC(int) _PyCoreConfig_GetEnvDup(
2649
wchar_t **dest,
2750
wchar_t *wname,
2851
char *name);
52+
PyAPI_FUNC(_PyInitError) _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config,
53+
const _PyArgv *args);
54+
PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config);
2955

3056
#ifdef __cplusplus
3157
}

‎Include/internal/pycore_pathconfig.h‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
99
#endif
1010

11-
PyAPI_FUNC(void) _Py_wstrlist_clear(
12-
int len,
13-
wchar_t **list);
14-
PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
15-
int len,
16-
wchar_t **list);
17-
PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
18-
int *len,
19-
wchar_t ***list,
20-
const wchar_t *str);
21-
PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(
22-
int len,
23-
wchar_t **list);
24-
2511
typedef struct _PyPathConfig {
2612
/* Full path to the Python program */
2713
wchar_t *program_full_path;

0 commit comments

Comments
 (0)