summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-10-01 08:56:37 (GMT)
committerGitHub <noreply@github.com>2019-10-01 08:56:37 (GMT)
commit3c30a76f3d3c0dcc1fb4de097fa4a3a4c92c0b0b (patch)
treebb73b56814d30967e67cc61eb8b66cab83477c3a /Python
parent94e165096fd65e8237e60de570fb609604ab94c9 (diff)
downloadcpython-3c30a76f3d3c0dcc1fb4de097fa4a3a4c92c0b0b.zip
cpython-3c30a76f3d3c0dcc1fb4de097fa4a3a4c92c0b0b.tar.gz
cpython-3c30a76f3d3c0dcc1fb4de097fa4a3a4c92c0b0b.tar.bz2
bpo-38304: Remove PyConfig.struct_size (GH-16500) (GH-16508)
For now, we'll rely on the fact that the config structures aren't covered by the stable ABI. We may revisit this in the future if we further explore the idea of offering a stable embedding API. (cherry picked from commit bdace21b769998396d0ccc8da99a8ca9b507bfdf)
Diffstat (limited to 'Python')
-rw-r--r--Python/frozenmain.c1
-rw-r--r--Python/initconfig.c38
-rw-r--r--Python/pathconfig.c1
-rw-r--r--Python/preconfig.c70
-rw-r--r--Python/pylifecycle.c9
-rw-r--r--Python/pystate.c7
6 files changed, 12 insertions, 114 deletions
diff --git a/Python/frozenmain.c b/Python/frozenmain.c
index 76309e9..c56938a 100644
--- a/Python/frozenmain.c
+++ b/Python/frozenmain.c
@@ -40,7 +40,6 @@ Py_FrozenMain(int argc, char **argv)
}
PyConfig config;
- config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
diff --git a/Python/initconfig.c b/Python/initconfig.c
index dec4bf2..107429c 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -529,17 +529,6 @@ Py_GetArgcArgv(int *argc, wchar_t ***argv)
: _PyStatus_NO_MEMORY())
-static PyStatus
-config_check_struct_size(const PyConfig *config)
-{
- if (config->struct_size != sizeof(PyConfig)) {
- return _PyStatus_ERR("unsupported PyConfig structure size "
- "(Python version mismatch?)");
- }
- return _PyStatus_OK();
-}
-
-
/* Free memory allocated in config, but don't clear all attributes */
void
PyConfig_Clear(PyConfig *config)
@@ -583,15 +572,7 @@ PyConfig_Clear(PyConfig *config)
PyStatus
_PyConfig_InitCompatConfig(PyConfig *config)
{
- size_t struct_size = config->struct_size;
memset(config, 0, sizeof(*config));
- config->struct_size = struct_size;
-
- PyStatus status = config_check_struct_size(config);
- if (_PyStatus_EXCEPTION(status)) {
- _PyStatus_UPDATE_FUNC(status);
- return status;
- }
config->_config_init = (int)_PyConfig_INIT_COMPAT;
config->isolated = -1;
@@ -775,18 +756,6 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
{
PyStatus status;
- status = config_check_struct_size(config);
- if (_PyStatus_EXCEPTION(status)) {
- _PyStatus_UPDATE_FUNC(status);
- return status;
- }
-
- status = config_check_struct_size(config2);
- if (_PyStatus_EXCEPTION(status)) {
- _PyStatus_UPDATE_FUNC(status);
- return status;
- }
-
PyConfig_Clear(config);
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
@@ -2280,7 +2249,6 @@ core_read_precmdline(PyConfig *config, _PyPreCmdline *precmdline)
}
PyPreConfig preconfig;
- preconfig.struct_size = sizeof(PyPreConfig);
status = _PyPreConfig_InitFromPreConfig(&preconfig, &_PyRuntime.preconfig);
if (_PyStatus_EXCEPTION(status)) {
@@ -2475,12 +2443,6 @@ PyConfig_Read(PyConfig *config)
PyStatus status;
PyWideStringList orig_argv = _PyWideStringList_INIT;
- status = config_check_struct_size(config);
- if (_PyStatus_EXCEPTION(status)) {
- _PyStatus_UPDATE_FUNC(status);
- return status;
- }
-
status = _Py_PreInitializeFromConfig(config, NULL);
if (_PyStatus_EXCEPTION(status)) {
return status;
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index 6886ab7..5550194 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -434,7 +434,6 @@ pathconfig_global_read(_PyPathConfig *pathconfig)
{
PyStatus status;
PyConfig config;
- config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
diff --git a/Python/preconfig.c b/Python/preconfig.c
index 01c72f5..89a6227 100644
--- a/Python/preconfig.c
+++ b/Python/preconfig.c
@@ -269,29 +269,10 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, const PyPreConfig *preconfig)
/* --- PyPreConfig ----------------------------------------------- */
-static PyStatus
-preconfig_check_struct_size(PyPreConfig *config)
-{
- if (config->struct_size != sizeof(PyPreConfig)) {
- return _PyStatus_ERR("unsupported PyPreConfig structure size "
- "(Python version mismatch?)");
- }
- return _PyStatus_OK();
-}
-
-
-PyStatus
+void
_PyPreConfig_InitCompatConfig(PyPreConfig *config)
{
- size_t struct_size = config->struct_size;
memset(config, 0, sizeof(*config));
- config->struct_size = struct_size;
-
- PyStatus status = preconfig_check_struct_size(config);
- if (_PyStatus_EXCEPTION(status)) {
- _PyStatus_UPDATE_FUNC(status);
- return status;
- }
config->_config_init = (int)_PyConfig_INIT_COMPAT;
config->parse_argv = 0;
@@ -313,18 +294,13 @@ _PyPreConfig_InitCompatConfig(PyPreConfig *config)
#ifdef MS_WINDOWS
config->legacy_windows_fs_encoding = -1;
#endif
- return _PyStatus_OK();
}
-PyStatus
+void
PyPreConfig_InitPythonConfig(PyPreConfig *config)
{
- PyStatus status = _PyPreConfig_InitCompatConfig(config);
- if (_PyStatus_EXCEPTION(status)) {
- _PyStatus_UPDATE_FUNC(status);
- return status;
- }
+ _PyPreConfig_InitCompatConfig(config);
config->_config_init = (int)_PyConfig_INIT_PYTHON;
config->isolated = 0;
@@ -339,18 +315,13 @@ PyPreConfig_InitPythonConfig(PyPreConfig *config)
#ifdef MS_WINDOWS
config->legacy_windows_fs_encoding = 0;
#endif
- return _PyStatus_OK();
}
-PyStatus
+void
PyPreConfig_InitIsolatedConfig(PyPreConfig *config)
{
- PyStatus status = _PyPreConfig_InitCompatConfig(config);
- if (_PyStatus_EXCEPTION(status)) {
- _PyStatus_UPDATE_FUNC(status);
- return status;
- }
+ _PyPreConfig_InitCompatConfig(config);
config->_config_init = (int)_PyConfig_INIT_ISOLATED;
config->configure_locale = 0;
@@ -361,7 +332,6 @@ PyPreConfig_InitIsolatedConfig(PyPreConfig *config)
#ifdef MS_WINDOWS
config->legacy_windows_fs_encoding = 0;
#endif
- return _PyStatus_OK();
}
@@ -369,47 +339,35 @@ PyStatus
_PyPreConfig_InitFromPreConfig(PyPreConfig *config,
const PyPreConfig *config2)
{
- PyStatus status = PyPreConfig_InitPythonConfig(config);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
-
+ PyPreConfig_InitPythonConfig(config);
preconfig_copy(config, config2);
return _PyStatus_OK();
}
-PyStatus
+void
_PyPreConfig_InitFromConfig(PyPreConfig *preconfig, const PyConfig *config)
{
- PyStatus status;
_PyConfigInitEnum config_init = (_PyConfigInitEnum)config->_config_init;
switch (config_init) {
case _PyConfig_INIT_PYTHON:
- status = PyPreConfig_InitPythonConfig(preconfig);
+ PyPreConfig_InitPythonConfig(preconfig);
break;
case _PyConfig_INIT_ISOLATED:
- status = PyPreConfig_InitIsolatedConfig(preconfig);
+ PyPreConfig_InitIsolatedConfig(preconfig);
break;
case _PyConfig_INIT_COMPAT:
default:
- status = _PyPreConfig_InitCompatConfig(preconfig);
- }
-
- if (_PyStatus_EXCEPTION(status)) {
- return status;
+ _PyPreConfig_InitCompatConfig(preconfig);
}
_PyPreConfig_GetConfig(preconfig, config);
- return _PyStatus_OK();
}
static void
preconfig_copy(PyPreConfig *config, const PyPreConfig *config2)
{
- assert(config->struct_size == sizeof(PyPreConfig));
-
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
COPY_ATTR(_config_init);
@@ -829,12 +787,6 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
return status;
}
- status = preconfig_check_struct_size(config);
- if (_PyStatus_EXCEPTION(status)) {
- _PyStatus_UPDATE_FUNC(status);
- return status;
- }
-
preconfig_get_global_vars(config);
/* Copy LC_CTYPE locale, since it's modified later */
@@ -849,7 +801,6 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
/* Save the config to be able to restore it if encodings change */
PyPreConfig save_config;
- save_config.struct_size = sizeof(PyPreConfig);
status = _PyPreConfig_InitFromPreConfig(&save_config, config);
if (_PyStatus_EXCEPTION(status)) {
@@ -976,7 +927,6 @@ PyStatus
_PyPreConfig_Write(const PyPreConfig *src_config)
{
PyPreConfig config;
- config.struct_size = sizeof(PyPreConfig);
PyStatus status = _PyPreConfig_InitFromPreConfig(&config, src_config);
if (_PyStatus_EXCEPTION(status)) {
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index ea0d7a5..019c56c 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -735,7 +735,6 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
runtime->preinitializing = 1;
PyPreConfig config;
- config.struct_size = sizeof(PyPreConfig);
status = _PyPreConfig_InitFromPreConfig(&config, src_config);
if (_PyStatus_EXCEPTION(status)) {
@@ -799,12 +798,8 @@ _Py_PreInitializeFromConfig(const PyConfig *config,
}
PyPreConfig preconfig;
- preconfig.struct_size = sizeof(PyPreConfig);
- status = _PyPreConfig_InitFromConfig(&preconfig, config);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
+ _PyPreConfig_InitFromConfig(&preconfig, config);
if (!config->parse_argv) {
return Py_PreInitialize(&preconfig);
@@ -852,7 +847,6 @@ pyinit_core(_PyRuntimeState *runtime,
}
PyConfig config;
- config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
@@ -1079,7 +1073,6 @@ Py_InitializeEx(int install_sigs)
}
PyConfig config;
- config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
diff --git a/Python/pystate.c b/Python/pystate.c
index 0f0cb22..69b86ce 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -61,11 +61,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
_PyGC_Initialize(&runtime->gc);
_PyEval_Initialize(&runtime->ceval);
- runtime->preconfig.struct_size = sizeof(PyPreConfig);
- PyStatus status = PyPreConfig_InitPythonConfig(&runtime->preconfig);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
+ PyPreConfig_InitPythonConfig(&runtime->preconfig);
runtime->gilstate.check_enabled = 1;
@@ -209,7 +205,6 @@ PyInterpreterState_New(void)
memset(interp, 0, sizeof(*interp));
interp->id_refcount = -1;
- interp->config.struct_size = sizeof(PyConfig);
PyStatus status = PyConfig_InitPythonConfig(&interp->config);
if (_PyStatus_EXCEPTION(status)) {
/* Don't report status to caller: PyConfig_InitPythonConfig()