Commit 8462a493 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-38304: PyConfig_InitPythonConfig() cannot fail anymore (GH-16509)

PyConfig_InitPythonConfig() and PyConfig_InitIsolatedConfig() no
longer return PyStatus: they cannot fail anymore.
parent 3c30a76f
...@@ -343,12 +343,12 @@ PyConfig ...@@ -343,12 +343,12 @@ PyConfig
Structure methods: Structure methods:
.. c:function:: PyStatus PyConfig_InitPythonConfig(PyConfig *config) .. c:function:: void PyConfig_InitPythonConfig(PyConfig *config)
Initialize configuration with :ref:`Python Configuration Initialize configuration with :ref:`Python Configuration
<init-python-config>`. <init-python-config>`.
.. c:function:: PyStatus PyConfig_InitIsolatedConfig(PyConfig *config) .. c:function:: void PyConfig_InitIsolatedConfig(PyConfig *config)
Initialize configuration with :ref:`Isolated Configuration Initialize configuration with :ref:`Isolated Configuration
<init-isolated-conf>`. <init-isolated-conf>`.
...@@ -724,12 +724,9 @@ Example setting the program name:: ...@@ -724,12 +724,9 @@ Example setting the program name::
void init_python(void) void init_python(void)
{ {
PyStatus status; PyStatus status;
PyConfig config;
status = PyConfig_InitPythonConfig(&config); PyConfig config;
if (PyStatus_Exception(status)) { PyConfig_InitPythonConfig(&config);
goto fail;
}
/* Set the program name. Implicitly preinitialize Python. */ /* Set the program name. Implicitly preinitialize Python. */
status = PyConfig_SetString(&config, &config.program_name, status = PyConfig_SetString(&config, &config.program_name,
...@@ -756,12 +753,9 @@ configuration, and then override some parameters:: ...@@ -756,12 +753,9 @@ configuration, and then override some parameters::
PyStatus init_python(const char *program_name) PyStatus init_python(const char *program_name)
{ {
PyStatus status; PyStatus status;
PyConfig config;
status = PyConfig_InitPythonConfig(&config); PyConfig config;
if (PyStatus_Exception(status)) { PyConfig_InitPythonConfig(&config);
goto done;
}
/* Set the program name before reading the configuraton /* Set the program name before reading the configuraton
(decode byte string from the locale encoding). (decode byte string from the locale encoding).
...@@ -843,13 +837,9 @@ Example of customized Python always running in isolated mode:: ...@@ -843,13 +837,9 @@ Example of customized Python always running in isolated mode::
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
PyStatus status; PyStatus status;
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
goto fail;
}
PyConfig config;
PyConfig_InitPythonConfig(&config);
config.isolated = 1; config.isolated = 1;
/* Decode command line arguments. /* Decode command line arguments.
...@@ -1034,14 +1024,9 @@ phases:: ...@@ -1034,14 +1024,9 @@ phases::
void init_python(void) void init_python(void)
{ {
PyStatus status; PyStatus status;
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
PyConfig config;
PyConfig_InitPythonConfig(&config);
config._init_main = 0; config._init_main = 0;
/* ... customize 'config' configuration ... */ /* ... customize 'config' configuration ... */
......
...@@ -404,8 +404,8 @@ typedef struct { ...@@ -404,8 +404,8 @@ typedef struct {
int _init_main; int _init_main;
} PyConfig; } PyConfig;
PyAPI_FUNC(PyStatus) PyConfig_InitPythonConfig(PyConfig *config); PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);
PyAPI_FUNC(PyStatus) PyConfig_InitIsolatedConfig(PyConfig *config); PyAPI_FUNC(void) PyConfig_InitIsolatedConfig(PyConfig *config);
PyAPI_FUNC(void) PyConfig_Clear(PyConfig *); PyAPI_FUNC(void) PyConfig_Clear(PyConfig *);
PyAPI_FUNC(PyStatus) PyConfig_SetString( PyAPI_FUNC(PyStatus) PyConfig_SetString(
PyConfig *config, PyConfig *config,
......
...@@ -144,7 +144,7 @@ typedef enum { ...@@ -144,7 +144,7 @@ typedef enum {
_PyConfig_INIT_ISOLATED = 3 _PyConfig_INIT_ISOLATED = 3
} _PyConfigInitEnum; } _PyConfigInitEnum;
PyAPI_FUNC(PyStatus) _PyConfig_InitCompatConfig(PyConfig *config); PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
extern PyStatus _PyConfig_Copy( extern PyStatus _PyConfig_Copy(
PyConfig *config, PyConfig *config,
const PyConfig *config2); const PyConfig *config2);
......
...@@ -61,11 +61,7 @@ pymain_init(const _PyArgv *args) ...@@ -61,11 +61,7 @@ pymain_init(const _PyArgv *args)
} }
PyConfig config; PyConfig config;
PyConfig_InitPythonConfig(&config);
status = PyConfig_InitPythonConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
/* pass NULL as the config: config is read from command line arguments, /* pass NULL as the config: config is read from command line arguments,
environment variables, configuration files */ environment variables, configuration files */
......
...@@ -193,10 +193,7 @@ wmain(int argc, wchar_t **argv) ...@@ -193,10 +193,7 @@ wmain(int argc, wchar_t **argv)
} }
} }
status = PyConfig_InitPythonConfig(&config); PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
goto fail_without_config;
}
status = PyConfig_SetArgv(&config, argc, argv); status = PyConfig_SetArgv(&config, argc, argv);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
......
...@@ -76,17 +76,12 @@ main(int argc, char *argv[]) ...@@ -76,17 +76,12 @@ main(int argc, char *argv[])
} }
text[text_size] = '\0'; text[text_size] = '\0';
PyStatus status;
PyConfig config; PyConfig config;
PyConfig_InitIsolatedConfig(&config);
status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
config.site_import = 0; config.site_import = 0;
PyStatus status;
status = PyConfig_SetString(&config, &config.program_name, status = PyConfig_SetString(&config, &config.program_name,
L"./_freeze_importlib"); L"./_freeze_importlib");
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
......
This diff is collapsed.
...@@ -40,11 +40,7 @@ Py_FrozenMain(int argc, char **argv) ...@@ -40,11 +40,7 @@ Py_FrozenMain(int argc, char **argv)
} }
PyConfig config; PyConfig config;
status = PyConfig_InitPythonConfig(&config); PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */ config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */
if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
......
...@@ -569,7 +569,7 @@ PyConfig_Clear(PyConfig *config) ...@@ -569,7 +569,7 @@ PyConfig_Clear(PyConfig *config)
} }
PyStatus void
_PyConfig_InitCompatConfig(PyConfig *config) _PyConfig_InitCompatConfig(PyConfig *config)
{ {
memset(config, 0, sizeof(*config)); memset(config, 0, sizeof(*config));
...@@ -603,17 +603,13 @@ _PyConfig_InitCompatConfig(PyConfig *config) ...@@ -603,17 +603,13 @@ _PyConfig_InitCompatConfig(PyConfig *config)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
config->legacy_windows_stdio = -1; config->legacy_windows_stdio = -1;
#endif #endif
return _PyStatus_OK();
} }
static PyStatus static void
config_init_defaults(PyConfig *config) config_init_defaults(PyConfig *config)
{ {
PyStatus status = _PyConfig_InitCompatConfig(config); _PyConfig_InitCompatConfig(config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
config->isolated = 0; config->isolated = 0;
config->use_environment = 1; config->use_environment = 1;
...@@ -632,35 +628,24 @@ config_init_defaults(PyConfig *config) ...@@ -632,35 +628,24 @@ config_init_defaults(PyConfig *config)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
config->legacy_windows_stdio = 0; config->legacy_windows_stdio = 0;
#endif #endif
return _PyStatus_OK();
} }
PyStatus void
PyConfig_InitPythonConfig(PyConfig *config) PyConfig_InitPythonConfig(PyConfig *config)
{ {
PyStatus status = config_init_defaults(config); config_init_defaults(config);
if (_PyStatus_EXCEPTION(status)) {
_PyStatus_UPDATE_FUNC(status);
return status;
}
config->_config_init = (int)_PyConfig_INIT_PYTHON; config->_config_init = (int)_PyConfig_INIT_PYTHON;
config->configure_c_stdio = 1; config->configure_c_stdio = 1;
config->parse_argv = 1; config->parse_argv = 1;
return _PyStatus_OK();
} }
PyStatus void
PyConfig_InitIsolatedConfig(PyConfig *config) PyConfig_InitIsolatedConfig(PyConfig *config)
{ {
PyStatus status = config_init_defaults(config); config_init_defaults(config);
if (_PyStatus_EXCEPTION(status)) {
_PyStatus_UPDATE_FUNC(status);
return status;
}
config->_config_init = (int)_PyConfig_INIT_ISOLATED; config->_config_init = (int)_PyConfig_INIT_ISOLATED;
config->isolated = 1; config->isolated = 1;
...@@ -675,8 +660,6 @@ PyConfig_InitIsolatedConfig(PyConfig *config) ...@@ -675,8 +660,6 @@ PyConfig_InitIsolatedConfig(PyConfig *config)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
config->legacy_windows_stdio = 0; config->legacy_windows_stdio = 0;
#endif #endif
return _PyStatus_OK();
} }
......
...@@ -432,16 +432,11 @@ _PyConfig_InitPathConfig(PyConfig *config) ...@@ -432,16 +432,11 @@ _PyConfig_InitPathConfig(PyConfig *config)
static PyStatus static PyStatus
pathconfig_global_read(_PyPathConfig *pathconfig) pathconfig_global_read(_PyPathConfig *pathconfig)
{ {
PyStatus status;
PyConfig config; PyConfig config;
_PyConfig_InitCompatConfig(&config);
status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
/* Call _PyConfig_InitPathConfig() */ /* Call _PyConfig_InitPathConfig() */
status = PyConfig_Read(&config); PyStatus status = PyConfig_Read(&config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
goto done; goto done;
} }
......
...@@ -847,11 +847,7 @@ pyinit_core(_PyRuntimeState *runtime, ...@@ -847,11 +847,7 @@ pyinit_core(_PyRuntimeState *runtime,
} }
PyConfig config; PyConfig config;
_PyConfig_InitCompatConfig(&config);
status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
status = _PyConfig_Copy(&config, src_config); status = _PyConfig_Copy(&config, src_config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
...@@ -1073,11 +1069,7 @@ Py_InitializeEx(int install_sigs) ...@@ -1073,11 +1069,7 @@ Py_InitializeEx(int install_sigs)
} }
PyConfig config; PyConfig config;
_PyConfig_InitCompatConfig(&config);
status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
Py_ExitStatusException(status);
}
config.install_signal_handlers = install_sigs; config.install_signal_handlers = install_sigs;
......
...@@ -205,14 +205,7 @@ PyInterpreterState_New(void) ...@@ -205,14 +205,7 @@ PyInterpreterState_New(void)
memset(interp, 0, sizeof(*interp)); memset(interp, 0, sizeof(*interp));
interp->id_refcount = -1; interp->id_refcount = -1;
PyStatus status = PyConfig_InitPythonConfig(&interp->config); PyConfig_InitPythonConfig(&interp->config);
if (_PyStatus_EXCEPTION(status)) {
/* Don't report status to caller: PyConfig_InitPythonConfig()
can only fail with a memory allocation error. */
PyConfig_Clear(&interp->config);
PyMem_RawFree(interp);
return NULL;
}
interp->eval_frame = _PyEval_EvalFrameDefault; interp->eval_frame = _PyEval_EvalFrameDefault;
#ifdef HAVE_DLOPEN #ifdef HAVE_DLOPEN
......
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