From 3c30a76f3d3c0dcc1fb4de097fa4a3a4c92c0b0b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 1 Oct 2019 10:56:37 +0200 Subject: [PATCH] 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) --- Doc/c-api/init_config.rst | 39 +------ Include/cpython/initconfig.h | 12 +- Include/internal/pycore_initconfig.h | 4 +- .../2019-09-28-03-43-27.bpo-38304.RqHAwd.rst | 3 - Modules/main.c | 9 +- PC/python_uwp.cpp | 9 +- Programs/_freeze_importlib.c | 1 - Programs/_testembed.c | 109 +++--------------- Python/frozenmain.c | 1 - Python/initconfig.c | 38 ------ Python/pathconfig.c | 1 - Python/preconfig.c | 70 ++--------- Python/pylifecycle.c | 9 +- Python/pystate.c | 7 +- 14 files changed, 39 insertions(+), 273 deletions(-) delete mode 100644 Misc/NEWS.d/next/C API/2019-09-28-03-43-27.bpo-38304.RqHAwd.rst diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index 4c77d5d1e0e..15b8b94d5a7 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -194,25 +194,18 @@ PyPreConfig * Configure the LC_CTYPE locale * Set the UTF-8 mode - The :c:member:`struct_size` field must be explicitly initialized to - ``sizeof(PyPreConfig)``. - Function to initialize a preconfiguration: - .. c:function:: PyStatus PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig) + .. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig) Initialize the preconfiguration with :ref:`Python Configuration `. - .. c:function:: PyStatus PyPreConfig_InitPythonConfig(PyPreConfig *preconfig) + .. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig) Initialize the preconfiguration with :ref:`Isolated Configuration `. - The caller of these functions is responsible to handle exceptions (error or - exit) using :c:func:`PyStatus_Exception` and - :c:func:`Py_ExitStatusException`. - Structure fields: .. c:member:: int allocator @@ -274,13 +267,6 @@ PyPreConfig same way the regular Python parses command line arguments: see :ref:`Command Line Arguments `. - .. c:member:: size_t struct_size - - Size of the structure in bytes: must be initialized to - ``sizeof(PyPreConfig)``. - - Field used for API and ABI compatibility. - .. c:member:: int use_environment See :c:member:`PyConfig.use_environment`. @@ -332,12 +318,7 @@ Example using the preinitialization to enable the UTF-8 Mode:: PyStatus status; PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = PyPreConfig_InitPythonConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + PyPreConfig_InitPythonConfig(&preconfig); preconfig.utf8_mode = 1; @@ -360,9 +341,6 @@ PyConfig Structure containing most parameters to configure Python. - The :c:member:`struct_size` field must be explicitly initialized to - ``sizeof(PyConfig)``. - Structure methods: .. c:function:: PyStatus PyConfig_InitPythonConfig(PyConfig *config) @@ -679,13 +657,6 @@ PyConfig Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and :data:`sys.stderr`. - .. c:member:: size_t struct_size - - Size of the structure in bytes: must be initialized to - ``sizeof(PyConfig)``. - - Field used for API and ABI compatibility. - .. c:member:: int tracemalloc If non-zero, call :func:`tracemalloc.start` at startup. @@ -754,7 +725,6 @@ Example setting the program name:: { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -787,7 +757,6 @@ configuration, and then override some parameters:: { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -875,7 +844,6 @@ Example of customized Python always running in isolated mode:: { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1067,7 +1035,6 @@ phases:: { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h index 8ce5622c5c4..25e02cea10d 100644 --- a/Include/cpython/initconfig.h +++ b/Include/cpython/initconfig.h @@ -45,10 +45,6 @@ PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list, /* --- PyPreConfig ----------------------------------------------- */ typedef struct { - /* Size of the structure in bytes: must be initialized to - sizeof(PyPreConfig). Field used for API and ABI compatibility. */ - size_t struct_size; - int _config_init; /* _PyConfigInitEnum value */ /* Parse Py_PreInitializeFromBytesArgs() arguments? @@ -124,17 +120,13 @@ typedef struct { int allocator; } PyPreConfig; -PyAPI_FUNC(PyStatus) PyPreConfig_InitPythonConfig(PyPreConfig *config); -PyAPI_FUNC(PyStatus) PyPreConfig_InitIsolatedConfig(PyPreConfig *config); +PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config); +PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config); /* --- PyConfig ---------------------------------------------- */ typedef struct { - /* Size of the structure in bytes: must be initialized to - sizeof(PyConfig). Field used for API and ABI compatibility. */ - size_t struct_size; - int _config_init; /* _PyConfigInitEnum value */ int isolated; /* Isolated mode? see PyPreConfig.isolated */ diff --git a/Include/internal/pycore_initconfig.h b/Include/internal/pycore_initconfig.h index eb6490f5a87..e9810bcf90a 100644 --- a/Include/internal/pycore_initconfig.h +++ b/Include/internal/pycore_initconfig.h @@ -120,8 +120,8 @@ extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline, /* --- PyPreConfig ----------------------------------------------- */ -PyAPI_FUNC(PyStatus) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig); -extern PyStatus _PyPreConfig_InitFromConfig( +PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig); +extern void _PyPreConfig_InitFromConfig( PyPreConfig *preconfig, const PyConfig *config); extern PyStatus _PyPreConfig_InitFromPreConfig( diff --git a/Misc/NEWS.d/next/C API/2019-09-28-03-43-27.bpo-38304.RqHAwd.rst b/Misc/NEWS.d/next/C API/2019-09-28-03-43-27.bpo-38304.RqHAwd.rst deleted file mode 100644 index b797933d05d..00000000000 --- a/Misc/NEWS.d/next/C API/2019-09-28-03-43-27.bpo-38304.RqHAwd.rst +++ /dev/null @@ -1,3 +0,0 @@ -Add a new ``struct_size`` field to :c:type:`PyPreConfig` and :c:type:`PyConfig` -structures to allow to modify these structures in the future without breaking -the backward compatibility. diff --git a/Modules/main.c b/Modules/main.c index ef6c66a8dbe..9cbf3ac7060 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -53,12 +53,7 @@ pymain_init(const _PyArgv *args) #endif PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = PyPreConfig_InitPythonConfig(&preconfig); - if (_PyStatus_EXCEPTION(status)) { - return status; - } + PyPreConfig_InitPythonConfig(&preconfig); status = _Py_PreInitializeFromPyArgv(&preconfig, args); if (_PyStatus_EXCEPTION(status)) { @@ -66,7 +61,7 @@ pymain_init(const _PyArgv *args) } PyConfig config; - config.struct_size = sizeof(PyConfig); + status = PyConfig_InitPythonConfig(&config); if (_PyStatus_EXCEPTION(status)) { goto done; diff --git a/PC/python_uwp.cpp b/PC/python_uwp.cpp index 2656d188c25..758c8f73725 100644 --- a/PC/python_uwp.cpp +++ b/PC/python_uwp.cpp @@ -165,12 +165,8 @@ int wmain(int argc, wchar_t **argv) { PyStatus status; - PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - PyConfig config; - config.struct_size = sizeof(PyConfig); const wchar_t *moduleName = NULL; const wchar_t *p = wcsrchr(argv[0], L'\\'); @@ -189,10 +185,7 @@ wmain(int argc, wchar_t **argv) } } - status = PyPreConfig_InitPythonConfig(&preconfig); - if (PyStatus_Exception(status)) { - goto fail_without_config; - } + PyPreConfig_InitPythonConfig(&preconfig); if (!moduleName) { status = Py_PreInitializeFromArgs(&preconfig, argc, argv); if (PyStatus_Exception(status)) { diff --git a/Programs/_freeze_importlib.c b/Programs/_freeze_importlib.c index 7c494c2786c..74735f279c5 100644 --- a/Programs/_freeze_importlib.c +++ b/Programs/_freeze_importlib.c @@ -78,7 +78,6 @@ main(int argc, char *argv[]) PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitIsolatedConfig(&config); if (PyStatus_Exception(status)) { diff --git a/Programs/_testembed.c b/Programs/_testembed.c index c8600d58f0b..d2d4c7f8c65 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -385,12 +385,7 @@ static int check_init_compat_config(int preinit) if (preinit) { PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = _PyPreConfig_InitCompatConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + _PyPreConfig_InitCompatConfig(&preconfig); status = Py_PreInitialize(&preconfig); if (PyStatus_Exception(status)) { @@ -399,7 +394,6 @@ static int check_init_compat_config(int preinit) } PyConfig config; - config.struct_size = sizeof(PyConfig); status = _PyConfig_InitCompatConfig(&config); if (PyStatus_Exception(status)) { @@ -478,15 +472,8 @@ static int test_init_global_config(void) static int test_init_from_config(void) { - PyStatus status; - PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = _PyPreConfig_InitCompatConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + _PyPreConfig_InitCompatConfig(&preconfig); putenv("PYTHONMALLOC=malloc_debug"); preconfig.allocator = PYMEM_ALLOCATOR_MALLOC; @@ -495,13 +482,12 @@ static int test_init_from_config(void) Py_UTF8Mode = 0; preconfig.utf8_mode = 1; - status = Py_PreInitialize(&preconfig); + PyStatus status = Py_PreInitialize(&preconfig); if (PyStatus_Exception(status)) { Py_ExitStatusException(status); } PyConfig config; - config.struct_size = sizeof(PyConfig); status = _PyConfig_InitCompatConfig(&config); if (PyStatus_Exception(status)) { @@ -638,7 +624,6 @@ static int check_init_parse_argv(int parse_argv) PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -725,7 +710,6 @@ static int test_init_python_env(void) set_all_env_vars(); PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -780,7 +764,6 @@ static int test_init_isolated_flag(void) /* Test PyConfig.isolated=1 */ PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -803,25 +786,17 @@ static int test_init_isolated_flag(void) /* PyPreConfig.isolated=1, PyConfig.isolated=0 */ static int test_preinit_isolated1(void) { - PyStatus status; - PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = _PyPreConfig_InitCompatConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + _PyPreConfig_InitCompatConfig(&preconfig); preconfig.isolated = 1; - status = Py_PreInitialize(&preconfig); + PyStatus status = Py_PreInitialize(&preconfig); if (PyStatus_Exception(status)) { Py_ExitStatusException(status); } PyConfig config; - config.struct_size = sizeof(PyConfig); status = _PyConfig_InitCompatConfig(&config); if (PyStatus_Exception(status)) { @@ -840,26 +815,19 @@ static int test_preinit_isolated1(void) /* PyPreConfig.isolated=0, PyConfig.isolated=1 */ static int test_preinit_isolated2(void) { - PyStatus status; - PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = _PyPreConfig_InitCompatConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + _PyPreConfig_InitCompatConfig(&preconfig); preconfig.isolated = 0; - status = Py_PreInitialize(&preconfig); + PyStatus status = Py_PreInitialize(&preconfig); if (PyStatus_Exception(status)) { Py_ExitStatusException(status); } /* Test PyConfig.isolated=1 */ PyConfig config; - config.struct_size = sizeof(PyConfig); + status = _PyConfig_InitCompatConfig(&config); if (PyStatus_Exception(status)) { Py_ExitStatusException(status); @@ -880,15 +848,8 @@ static int test_preinit_isolated2(void) static int test_preinit_dont_parse_argv(void) { - PyStatus status; - PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = PyPreConfig_InitIsolatedConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + PyPreConfig_InitIsolatedConfig(&preconfig); preconfig.isolated = 0; @@ -899,13 +860,13 @@ static int test_preinit_dont_parse_argv(void) L"-X", L"dev", L"-X", L"utf8", L"script.py"}; - status = Py_PreInitializeFromArgs(&preconfig, Py_ARRAY_LENGTH(argv), argv); + PyStatus status = Py_PreInitializeFromArgs(&preconfig, + Py_ARRAY_LENGTH(argv), argv); if (PyStatus_Exception(status)) { Py_ExitStatusException(status); } PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitIsolatedConfig(&config); if (PyStatus_Exception(status)) { @@ -931,7 +892,6 @@ static int test_preinit_parse_argv(void) { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -989,12 +949,7 @@ static int check_preinit_isolated_config(int preinit) if (preinit) { PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = PyPreConfig_InitIsolatedConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + PyPreConfig_InitIsolatedConfig(&preconfig); status = Py_PreInitialize(&preconfig); if (PyStatus_Exception(status)) { @@ -1007,7 +962,6 @@ static int check_preinit_isolated_config(int preinit) } PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitIsolatedConfig(&config); if (PyStatus_Exception(status)) { @@ -1058,12 +1012,7 @@ static int check_init_python_config(int preinit) if (preinit) { PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = PyPreConfig_InitPythonConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + PyPreConfig_InitPythonConfig(&preconfig); status = Py_PreInitialize(&preconfig); if (PyStatus_Exception(status)) { @@ -1072,7 +1021,6 @@ static int check_init_python_config(int preinit) } PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1101,27 +1049,19 @@ static int test_init_python_config(void) static int test_init_dont_configure_locale(void) { - PyStatus status; - PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = PyPreConfig_InitPythonConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + PyPreConfig_InitPythonConfig(&preconfig); preconfig.configure_locale = 0; preconfig.coerce_c_locale = 1; preconfig.coerce_c_locale_warn = 1; - status = Py_PreInitialize(&preconfig); + PyStatus status = Py_PreInitialize(&preconfig); if (PyStatus_Exception(status)) { Py_ExitStatusException(status); } PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1140,7 +1080,6 @@ static int test_init_dev_mode(void) { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1365,7 +1304,6 @@ static int run_audit_run_test(int argc, wchar_t **argv, void *test) { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1415,7 +1353,6 @@ static int test_init_read_set(void) { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1465,7 +1402,6 @@ static int test_init_sys_add(void) PySys_AddWarnOption(L"ignore:::sysadd_warnoption"); PyConfig config; - config.struct_size = sizeof(PyConfig); PyStatus status; status = PyConfig_InitPythonConfig(&config); @@ -1533,18 +1469,12 @@ static int test_init_setpath(void) static int test_init_setpath_config(void) { - PyStatus status; PyPreConfig preconfig; - preconfig.struct_size = sizeof(PyPreConfig); - - status = PyPreConfig_InitPythonConfig(&preconfig); - if (PyStatus_Exception(status)) { - Py_ExitStatusException(status); - } + PyPreConfig_InitPythonConfig(&preconfig); /* Explicitly preinitializes with Python preconfiguration to avoid Py_SetPath() implicit preinitialization with compat preconfiguration. */ - status = Py_PreInitialize(&preconfig); + PyStatus status = Py_PreInitialize(&preconfig); if (PyStatus_Exception(status)) { Py_ExitStatusException(status); } @@ -1564,7 +1494,6 @@ static int test_init_setpath_config(void) putenv("TESTPATH="); PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1612,7 +1541,6 @@ static int test_init_warnoptions(void) PySys_AddWarnOption(L"ignore:::PySys_AddWarnOption2"); PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1680,7 +1608,6 @@ static int test_init_run_main(void) { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1697,7 +1624,6 @@ static int test_init_main(void) { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { @@ -1729,7 +1655,6 @@ static int test_run_main(void) { PyStatus status; PyConfig config; - config.struct_size = sizeof(PyConfig); status = PyConfig_InitPythonConfig(&config); if (PyStatus_Exception(status)) { diff --git a/Python/frozenmain.c b/Python/frozenmain.c index 76309e9e5da..c56938ab489 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 dec4bf2e4d5..107429c7ec3 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 6886ab7c42d..5550194a5d5 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 01c72f5d6ba..89a6227fa67 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 ea0d7a5ee2b..019c56c3f8b 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 0f0cb229955..69b86ce4f7a 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()