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