bpo-36301: Cleanup preconfig.c and coreconfig.c (GH-12563)
* _PyCoreConfig_Write() now updates _PyRuntime.preconfig
* Remove _PyPreCmdline_Copy()
* _PyPreCmdline_Read() now accepts _PyPreConfig and _PyCoreConfig
optional configurations.
* Rename _PyPreConfig_ReadFromArgv() to _PyPreConfig_Read(). Simplify
the code.
* Calling _PyCoreConfig_Read() no longer adds the warning options
twice: don't add a warning option if it's already in the list.
* Rename _PyCoreConfig_ReadFromArgv() to _PyCoreConfig_Read().
* Rename config_from_cmdline() to _PyCoreConfig_ReadFromArgv().
* Add more assertions on _PyCoreConfig in _PyCoreConfig_Read().
* Move some functions.
* Make some config functions private.
diff --git a/Include/cpython/pylifecycle.h b/Include/cpython/pylifecycle.h
index e32e54c..0c5f74e 100644
--- a/Include/cpython/pylifecycle.h
+++ b/Include/cpython/pylifecycle.h
@@ -21,8 +21,8 @@
const _PyCoreConfig *coreconfig);
PyAPI_FUNC(_PyInitError) _Py_InitializeCore(
- PyInterpreterState **interp,
- const _PyCoreConfig *);
+ const _PyCoreConfig *config,
+ PyInterpreterState **interp);
PyAPI_FUNC(int) _Py_IsCoreInitialized(void);
diff --git a/Include/internal/pycore_coreconfig.h b/Include/internal/pycore_coreconfig.h
index d79f590..dad5d3f 100644
--- a/Include/internal/pycore_coreconfig.h
+++ b/Include/internal/pycore_coreconfig.h
@@ -14,8 +14,8 @@
typedef struct {
_PyWstrList argv;
_PyWstrList xoptions; /* "-X value" option */
- int use_environment; /* -E option */
int isolated; /* -I option */
+ int use_environment; /* -E option */
int dev_mode; /* -X dev and PYTHONDEVMODE */
} _PyPreCmdline;
@@ -27,23 +27,14 @@
/* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */
PyAPI_FUNC(void) _PyPreCmdline_Clear(_PyPreCmdline *cmdline);
-PyAPI_FUNC(int) _PyPreCmdline_Copy(_PyPreCmdline *cmdline,
- const _PyPreCmdline *cmdline2);
PyAPI_FUNC(_PyInitError) _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline,
const _PyArgv *args);
-PyAPI_FUNC(void) _PyPreCmdline_GetPreConfig(
- _PyPreCmdline *cmdline,
- const _PyPreConfig *config);
-PyAPI_FUNC(void) _PyPreCmdline_SetPreConfig(
- const _PyPreCmdline *cmdline,
- _PyPreConfig *config);
-PyAPI_FUNC(void) _PyPreCmdline_GetCoreConfig(
- _PyPreCmdline *cmdline,
- const _PyCoreConfig *config);
-PyAPI_FUNC(void) _PyPreCmdline_SetCoreConfig(
+PyAPI_FUNC(int) _PyPreCmdline_SetCoreConfig(
const _PyPreCmdline *cmdline,
_PyCoreConfig *config);
-PyAPI_FUNC(_PyInitError) _PyPreCmdline_Read(_PyPreCmdline *cmdline);
+PyAPI_FUNC(_PyInitError) _PyPreCmdline_Read(_PyPreCmdline *cmdline,
+ const _PyPreConfig *preconfig,
+ const _PyCoreConfig *coreconfig);
/* --- _PyWstrList ------------------------------------------------ */
@@ -57,6 +48,8 @@
PyAPI_FUNC(int) _PyWstrList_Append(_PyWstrList *list,
const wchar_t *item);
PyAPI_FUNC(PyObject*) _PyWstrList_AsList(const _PyWstrList *list);
+PyAPI_FUNC(int) _PyWstrList_Extend(_PyWstrList *list,
+ const _PyWstrList *list2);
/* --- _PyArgv ---------------------------------------------------- */
@@ -70,7 +63,7 @@
PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
-/* --- _PyPreConfig ----------------------------------------------- */
+/* --- Helper functions ------------------------------------------- */
PyAPI_FUNC(int) _Py_str_to_int(
const char *str,
@@ -81,22 +74,20 @@
PyAPI_FUNC(const char*) _Py_GetEnv(
int use_environment,
const char *name);
-
-PyAPI_FUNC(void) _PyPreConfig_Clear(_PyPreConfig *config);
-PyAPI_FUNC(int) _PyPreConfig_Copy(_PyPreConfig *config,
- const _PyPreConfig *config2);
-PyAPI_FUNC(void) _PyPreConfig_GetGlobalConfig(_PyPreConfig *config);
-PyAPI_FUNC(void) _PyPreConfig_SetGlobalConfig(const _PyPreConfig *config);
PyAPI_FUNC(void) _Py_get_env_flag(
int use_environment,
int *flag,
const char *name);
+
+/* --- _PyPreConfig ----------------------------------------------- */
+
+PyAPI_FUNC(void) _PyPreConfig_Clear(_PyPreConfig *config);
+PyAPI_FUNC(int) _PyPreConfig_Copy(_PyPreConfig *config,
+ const _PyPreConfig *config2);
+PyAPI_FUNC(PyObject*) _PyPreConfig_AsDict(const _PyPreConfig *config);
PyAPI_FUNC(_PyInitError) _PyPreConfig_Read(_PyPreConfig *config,
const _PyArgv *args,
const _PyCoreConfig *coreconfig);
-PyAPI_FUNC(PyObject*) _PyPreConfig_AsDict(const _PyPreConfig *config);
-PyAPI_FUNC(_PyInitError) _PyPreConfig_ReadFromArgv(_PyPreConfig *config,
- const _PyArgv *args);
PyAPI_FUNC(_PyInitError) _PyPreConfig_Write(_PyPreConfig *config);
@@ -109,10 +100,7 @@
PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig(_PyCoreConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPathConfig(
const _PyCoreConfig *config);
-PyAPI_FUNC(void) _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config);
-PyAPI_FUNC(void) _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config);
-PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config);
-PyAPI_FUNC(_PyInitError) _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config,
+PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config,
const _PyArgv *args);
PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config);