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 bdace21b76)
This commit is contained in:
Victor Stinner 2019-10-01 10:56:37 +02:00 committed by GitHub
parent 94e165096f
commit 3c30a76f3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 39 additions and 273 deletions

View File

@ -194,25 +194,18 @@ PyPreConfig
* Configure the LC_CTYPE locale * Configure the LC_CTYPE locale
* Set the UTF-8 mode * Set the UTF-8 mode
The :c:member:`struct_size` field must be explicitly initialized to
``sizeof(PyPreConfig)``.
Function to initialize a preconfiguration: 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 Initialize the preconfiguration with :ref:`Python Configuration
<init-python-config>`. <init-python-config>`.
.. c:function:: PyStatus PyPreConfig_InitPythonConfig(PyPreConfig *preconfig) .. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
Initialize the preconfiguration with :ref:`Isolated Configuration Initialize the preconfiguration with :ref:`Isolated Configuration
<init-isolated-conf>`. <init-isolated-conf>`.
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: Structure fields:
.. c:member:: int allocator .. c:member:: int allocator
@ -274,13 +267,6 @@ PyPreConfig
same way the regular Python parses command line arguments: see same way the regular Python parses command line arguments: see
:ref:`Command Line Arguments <using-on-cmdline>`. :ref:`Command Line Arguments <using-on-cmdline>`.
.. 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 .. c:member:: int use_environment
See :c:member:`PyConfig.use_environment`. See :c:member:`PyConfig.use_environment`.
@ -332,12 +318,7 @@ Example using the preinitialization to enable the UTF-8 Mode::
PyStatus status; PyStatus status;
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); PyPreConfig_InitPythonConfig(&preconfig);
status = PyPreConfig_InitPythonConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
preconfig.utf8_mode = 1; preconfig.utf8_mode = 1;
@ -360,9 +341,6 @@ PyConfig
Structure containing most parameters to configure Python. Structure containing most parameters to configure Python.
The :c:member:`struct_size` field must be explicitly initialized to
``sizeof(PyConfig)``.
Structure methods: Structure methods:
.. c:function:: PyStatus PyConfig_InitPythonConfig(PyConfig *config) .. c:function:: PyStatus PyConfig_InitPythonConfig(PyConfig *config)
@ -679,13 +657,6 @@ PyConfig
Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and
:data:`sys.stderr`. :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 .. c:member:: int tracemalloc
If non-zero, call :func:`tracemalloc.start` at startup. If non-zero, call :func:`tracemalloc.start` at startup.
@ -754,7 +725,6 @@ Example setting the program name::
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -787,7 +757,6 @@ configuration, and then override some parameters::
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -875,7 +844,6 @@ Example of customized Python always running in isolated mode::
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1067,7 +1035,6 @@ phases::
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {

View File

@ -45,10 +45,6 @@ PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list,
/* --- PyPreConfig ----------------------------------------------- */ /* --- PyPreConfig ----------------------------------------------- */
typedef struct { 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 */ int _config_init; /* _PyConfigInitEnum value */
/* Parse Py_PreInitializeFromBytesArgs() arguments? /* Parse Py_PreInitializeFromBytesArgs() arguments?
@ -124,17 +120,13 @@ typedef struct {
int allocator; int allocator;
} PyPreConfig; } PyPreConfig;
PyAPI_FUNC(PyStatus) PyPreConfig_InitPythonConfig(PyPreConfig *config); PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
PyAPI_FUNC(PyStatus) PyPreConfig_InitIsolatedConfig(PyPreConfig *config); PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
/* --- PyConfig ---------------------------------------------- */ /* --- PyConfig ---------------------------------------------- */
typedef struct { 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 _config_init; /* _PyConfigInitEnum value */
int isolated; /* Isolated mode? see PyPreConfig.isolated */ int isolated; /* Isolated mode? see PyPreConfig.isolated */

View File

@ -120,8 +120,8 @@ extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,
/* --- PyPreConfig ----------------------------------------------- */ /* --- PyPreConfig ----------------------------------------------- */
PyAPI_FUNC(PyStatus) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig); PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
extern PyStatus _PyPreConfig_InitFromConfig( extern void _PyPreConfig_InitFromConfig(
PyPreConfig *preconfig, PyPreConfig *preconfig,
const PyConfig *config); const PyConfig *config);
extern PyStatus _PyPreConfig_InitFromPreConfig( extern PyStatus _PyPreConfig_InitFromPreConfig(

View File

@ -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.

View File

@ -53,12 +53,7 @@ pymain_init(const _PyArgv *args)
#endif #endif
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); PyPreConfig_InitPythonConfig(&preconfig);
status = PyPreConfig_InitPythonConfig(&preconfig);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
status = _Py_PreInitializeFromPyArgv(&preconfig, args); status = _Py_PreInitializeFromPyArgv(&preconfig, args);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
@ -66,7 +61,7 @@ pymain_init(const _PyArgv *args)
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
goto done; goto done;

View File

@ -165,12 +165,8 @@ int
wmain(int argc, wchar_t **argv) wmain(int argc, wchar_t **argv)
{ {
PyStatus status; PyStatus status;
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig);
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
const wchar_t *moduleName = NULL; const wchar_t *moduleName = NULL;
const wchar_t *p = wcsrchr(argv[0], L'\\'); const wchar_t *p = wcsrchr(argv[0], L'\\');
@ -189,10 +185,7 @@ wmain(int argc, wchar_t **argv)
} }
} }
status = PyPreConfig_InitPythonConfig(&preconfig); PyPreConfig_InitPythonConfig(&preconfig);
if (PyStatus_Exception(status)) {
goto fail_without_config;
}
if (!moduleName) { if (!moduleName) {
status = Py_PreInitializeFromArgs(&preconfig, argc, argv); status = Py_PreInitializeFromArgs(&preconfig, argc, argv);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {

View File

@ -78,7 +78,6 @@ main(int argc, char *argv[])
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitIsolatedConfig(&config); status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {

View File

@ -385,12 +385,7 @@ static int check_init_compat_config(int preinit)
if (preinit) { if (preinit) {
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); _PyPreConfig_InitCompatConfig(&preconfig);
status = _PyPreConfig_InitCompatConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
status = Py_PreInitialize(&preconfig); status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -399,7 +394,6 @@ static int check_init_compat_config(int preinit)
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config); status = _PyConfig_InitCompatConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -478,15 +472,8 @@ static int test_init_global_config(void)
static int test_init_from_config(void) static int test_init_from_config(void)
{ {
PyStatus status;
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); _PyPreConfig_InitCompatConfig(&preconfig);
status = _PyPreConfig_InitCompatConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
putenv("PYTHONMALLOC=malloc_debug"); putenv("PYTHONMALLOC=malloc_debug");
preconfig.allocator = PYMEM_ALLOCATOR_MALLOC; preconfig.allocator = PYMEM_ALLOCATOR_MALLOC;
@ -495,13 +482,12 @@ static int test_init_from_config(void)
Py_UTF8Mode = 0; Py_UTF8Mode = 0;
preconfig.utf8_mode = 1; preconfig.utf8_mode = 1;
status = Py_PreInitialize(&preconfig); PyStatus status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
Py_ExitStatusException(status); Py_ExitStatusException(status);
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config); status = _PyConfig_InitCompatConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -638,7 +624,6 @@ static int check_init_parse_argv(int parse_argv)
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -725,7 +710,6 @@ static int test_init_python_env(void)
set_all_env_vars(); set_all_env_vars();
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -780,7 +764,6 @@ static int test_init_isolated_flag(void)
/* Test PyConfig.isolated=1 */ /* Test PyConfig.isolated=1 */
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -803,25 +786,17 @@ static int test_init_isolated_flag(void)
/* PyPreConfig.isolated=1, PyConfig.isolated=0 */ /* PyPreConfig.isolated=1, PyConfig.isolated=0 */
static int test_preinit_isolated1(void) static int test_preinit_isolated1(void)
{ {
PyStatus status;
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); _PyPreConfig_InitCompatConfig(&preconfig);
status = _PyPreConfig_InitCompatConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
preconfig.isolated = 1; preconfig.isolated = 1;
status = Py_PreInitialize(&preconfig); PyStatus status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
Py_ExitStatusException(status); Py_ExitStatusException(status);
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config); status = _PyConfig_InitCompatConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -840,26 +815,19 @@ static int test_preinit_isolated1(void)
/* PyPreConfig.isolated=0, PyConfig.isolated=1 */ /* PyPreConfig.isolated=0, PyConfig.isolated=1 */
static int test_preinit_isolated2(void) static int test_preinit_isolated2(void)
{ {
PyStatus status;
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); _PyPreConfig_InitCompatConfig(&preconfig);
status = _PyPreConfig_InitCompatConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
preconfig.isolated = 0; preconfig.isolated = 0;
status = Py_PreInitialize(&preconfig); PyStatus status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
Py_ExitStatusException(status); Py_ExitStatusException(status);
} }
/* Test PyConfig.isolated=1 */ /* Test PyConfig.isolated=1 */
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config); status = _PyConfig_InitCompatConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
Py_ExitStatusException(status); Py_ExitStatusException(status);
@ -880,15 +848,8 @@ static int test_preinit_isolated2(void)
static int test_preinit_dont_parse_argv(void) static int test_preinit_dont_parse_argv(void)
{ {
PyStatus status;
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); PyPreConfig_InitIsolatedConfig(&preconfig);
status = PyPreConfig_InitIsolatedConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
preconfig.isolated = 0; preconfig.isolated = 0;
@ -899,13 +860,13 @@ static int test_preinit_dont_parse_argv(void)
L"-X", L"dev", L"-X", L"dev",
L"-X", L"utf8", L"-X", L"utf8",
L"script.py"}; 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)) { if (PyStatus_Exception(status)) {
Py_ExitStatusException(status); Py_ExitStatusException(status);
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitIsolatedConfig(&config); status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -931,7 +892,6 @@ static int test_preinit_parse_argv(void)
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -989,12 +949,7 @@ static int check_preinit_isolated_config(int preinit)
if (preinit) { if (preinit) {
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); PyPreConfig_InitIsolatedConfig(&preconfig);
status = PyPreConfig_InitIsolatedConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
status = Py_PreInitialize(&preconfig); status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1007,7 +962,6 @@ static int check_preinit_isolated_config(int preinit)
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitIsolatedConfig(&config); status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1058,12 +1012,7 @@ static int check_init_python_config(int preinit)
if (preinit) { if (preinit) {
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); PyPreConfig_InitPythonConfig(&preconfig);
status = PyPreConfig_InitPythonConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
status = Py_PreInitialize(&preconfig); status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1072,7 +1021,6 @@ static int check_init_python_config(int preinit)
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1101,27 +1049,19 @@ static int test_init_python_config(void)
static int test_init_dont_configure_locale(void) static int test_init_dont_configure_locale(void)
{ {
PyStatus status;
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); PyPreConfig_InitPythonConfig(&preconfig);
status = PyPreConfig_InitPythonConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
preconfig.configure_locale = 0; preconfig.configure_locale = 0;
preconfig.coerce_c_locale = 1; preconfig.coerce_c_locale = 1;
preconfig.coerce_c_locale_warn = 1; preconfig.coerce_c_locale_warn = 1;
status = Py_PreInitialize(&preconfig); PyStatus status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
Py_ExitStatusException(status); Py_ExitStatusException(status);
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1140,7 +1080,6 @@ static int test_init_dev_mode(void)
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1365,7 +1304,6 @@ static int run_audit_run_test(int argc, wchar_t **argv, void *test)
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1415,7 +1353,6 @@ static int test_init_read_set(void)
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1465,7 +1402,6 @@ static int test_init_sys_add(void)
PySys_AddWarnOption(L"ignore:::sysadd_warnoption"); PySys_AddWarnOption(L"ignore:::sysadd_warnoption");
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
PyStatus status; PyStatus status;
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
@ -1533,18 +1469,12 @@ static int test_init_setpath(void)
static int test_init_setpath_config(void) static int test_init_setpath_config(void)
{ {
PyStatus status;
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig); PyPreConfig_InitPythonConfig(&preconfig);
status = PyPreConfig_InitPythonConfig(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
/* Explicitly preinitializes with Python preconfiguration to avoid /* Explicitly preinitializes with Python preconfiguration to avoid
Py_SetPath() implicit preinitialization with compat preconfiguration. */ Py_SetPath() implicit preinitialization with compat preconfiguration. */
status = Py_PreInitialize(&preconfig); PyStatus status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
Py_ExitStatusException(status); Py_ExitStatusException(status);
} }
@ -1564,7 +1494,6 @@ static int test_init_setpath_config(void)
putenv("TESTPATH="); putenv("TESTPATH=");
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1612,7 +1541,6 @@ static int test_init_warnoptions(void)
PySys_AddWarnOption(L"ignore:::PySys_AddWarnOption2"); PySys_AddWarnOption(L"ignore:::PySys_AddWarnOption2");
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1680,7 +1608,6 @@ static int test_init_run_main(void)
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1697,7 +1624,6 @@ static int test_init_main(void)
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
@ -1729,7 +1655,6 @@ static int test_run_main(void)
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {

View File

@ -40,7 +40,6 @@ Py_FrozenMain(int argc, char **argv)
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
PyConfig_Clear(&config); PyConfig_Clear(&config);

View File

@ -529,17 +529,6 @@ Py_GetArgcArgv(int *argc, wchar_t ***argv)
: _PyStatus_NO_MEMORY()) : _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 */ /* Free memory allocated in config, but don't clear all attributes */
void void
PyConfig_Clear(PyConfig *config) PyConfig_Clear(PyConfig *config)
@ -583,15 +572,7 @@ PyConfig_Clear(PyConfig *config)
PyStatus PyStatus
_PyConfig_InitCompatConfig(PyConfig *config) _PyConfig_InitCompatConfig(PyConfig *config)
{ {
size_t struct_size = config->struct_size;
memset(config, 0, sizeof(*config)); 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->_config_init = (int)_PyConfig_INIT_COMPAT;
config->isolated = -1; config->isolated = -1;
@ -775,18 +756,6 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
{ {
PyStatus status; 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); PyConfig_Clear(config);
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR #define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
@ -2280,7 +2249,6 @@ core_read_precmdline(PyConfig *config, _PyPreCmdline *precmdline)
} }
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig);
status = _PyPreConfig_InitFromPreConfig(&preconfig, &_PyRuntime.preconfig); status = _PyPreConfig_InitFromPreConfig(&preconfig, &_PyRuntime.preconfig);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
@ -2475,12 +2443,6 @@ PyConfig_Read(PyConfig *config)
PyStatus status; PyStatus status;
PyWideStringList orig_argv = _PyWideStringList_INIT; 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); status = _Py_PreInitializeFromConfig(config, NULL);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
return status; return status;

View File

@ -434,7 +434,6 @@ pathconfig_global_read(_PyPathConfig *pathconfig)
{ {
PyStatus status; PyStatus status;
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config); status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {

View File

@ -269,29 +269,10 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, const PyPreConfig *preconfig)
/* --- PyPreConfig ----------------------------------------------- */ /* --- PyPreConfig ----------------------------------------------- */
static PyStatus void
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
_PyPreConfig_InitCompatConfig(PyPreConfig *config) _PyPreConfig_InitCompatConfig(PyPreConfig *config)
{ {
size_t struct_size = config->struct_size;
memset(config, 0, sizeof(*config)); 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->_config_init = (int)_PyConfig_INIT_COMPAT;
config->parse_argv = 0; config->parse_argv = 0;
@ -313,18 +294,13 @@ _PyPreConfig_InitCompatConfig(PyPreConfig *config)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
config->legacy_windows_fs_encoding = -1; config->legacy_windows_fs_encoding = -1;
#endif #endif
return _PyStatus_OK();
} }
PyStatus void
PyPreConfig_InitPythonConfig(PyPreConfig *config) PyPreConfig_InitPythonConfig(PyPreConfig *config)
{ {
PyStatus status = _PyPreConfig_InitCompatConfig(config); _PyPreConfig_InitCompatConfig(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->isolated = 0; config->isolated = 0;
@ -339,18 +315,13 @@ PyPreConfig_InitPythonConfig(PyPreConfig *config)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
config->legacy_windows_fs_encoding = 0; config->legacy_windows_fs_encoding = 0;
#endif #endif
return _PyStatus_OK();
} }
PyStatus void
PyPreConfig_InitIsolatedConfig(PyPreConfig *config) PyPreConfig_InitIsolatedConfig(PyPreConfig *config)
{ {
PyStatus status = _PyPreConfig_InitCompatConfig(config); _PyPreConfig_InitCompatConfig(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->configure_locale = 0; config->configure_locale = 0;
@ -361,7 +332,6 @@ PyPreConfig_InitIsolatedConfig(PyPreConfig *config)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
config->legacy_windows_fs_encoding = 0; config->legacy_windows_fs_encoding = 0;
#endif #endif
return _PyStatus_OK();
} }
@ -369,47 +339,35 @@ PyStatus
_PyPreConfig_InitFromPreConfig(PyPreConfig *config, _PyPreConfig_InitFromPreConfig(PyPreConfig *config,
const PyPreConfig *config2) const PyPreConfig *config2)
{ {
PyStatus status = PyPreConfig_InitPythonConfig(config); PyPreConfig_InitPythonConfig(config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
preconfig_copy(config, config2); preconfig_copy(config, config2);
return _PyStatus_OK(); return _PyStatus_OK();
} }
PyStatus void
_PyPreConfig_InitFromConfig(PyPreConfig *preconfig, const PyConfig *config) _PyPreConfig_InitFromConfig(PyPreConfig *preconfig, const PyConfig *config)
{ {
PyStatus status;
_PyConfigInitEnum config_init = (_PyConfigInitEnum)config->_config_init; _PyConfigInitEnum config_init = (_PyConfigInitEnum)config->_config_init;
switch (config_init) { switch (config_init) {
case _PyConfig_INIT_PYTHON: case _PyConfig_INIT_PYTHON:
status = PyPreConfig_InitPythonConfig(preconfig); PyPreConfig_InitPythonConfig(preconfig);
break; break;
case _PyConfig_INIT_ISOLATED: case _PyConfig_INIT_ISOLATED:
status = PyPreConfig_InitIsolatedConfig(preconfig); PyPreConfig_InitIsolatedConfig(preconfig);
break; break;
case _PyConfig_INIT_COMPAT: case _PyConfig_INIT_COMPAT:
default: default:
status = _PyPreConfig_InitCompatConfig(preconfig); _PyPreConfig_InitCompatConfig(preconfig);
}
if (_PyStatus_EXCEPTION(status)) {
return status;
} }
_PyPreConfig_GetConfig(preconfig, config); _PyPreConfig_GetConfig(preconfig, config);
return _PyStatus_OK();
} }
static void static void
preconfig_copy(PyPreConfig *config, const PyPreConfig *config2) preconfig_copy(PyPreConfig *config, const PyPreConfig *config2)
{ {
assert(config->struct_size == sizeof(PyPreConfig));
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR #define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
COPY_ATTR(_config_init); COPY_ATTR(_config_init);
@ -829,12 +787,6 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
return status; return status;
} }
status = preconfig_check_struct_size(config);
if (_PyStatus_EXCEPTION(status)) {
_PyStatus_UPDATE_FUNC(status);
return status;
}
preconfig_get_global_vars(config); preconfig_get_global_vars(config);
/* Copy LC_CTYPE locale, since it's modified later */ /* 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 */ /* Save the config to be able to restore it if encodings change */
PyPreConfig save_config; PyPreConfig save_config;
save_config.struct_size = sizeof(PyPreConfig);
status = _PyPreConfig_InitFromPreConfig(&save_config, config); status = _PyPreConfig_InitFromPreConfig(&save_config, config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
@ -976,7 +927,6 @@ PyStatus
_PyPreConfig_Write(const PyPreConfig *src_config) _PyPreConfig_Write(const PyPreConfig *src_config)
{ {
PyPreConfig config; PyPreConfig config;
config.struct_size = sizeof(PyPreConfig);
PyStatus status = _PyPreConfig_InitFromPreConfig(&config, src_config); PyStatus status = _PyPreConfig_InitFromPreConfig(&config, src_config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {

View File

@ -735,7 +735,6 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
runtime->preinitializing = 1; runtime->preinitializing = 1;
PyPreConfig config; PyPreConfig config;
config.struct_size = sizeof(PyPreConfig);
status = _PyPreConfig_InitFromPreConfig(&config, src_config); status = _PyPreConfig_InitFromPreConfig(&config, src_config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
@ -799,12 +798,8 @@ _Py_PreInitializeFromConfig(const PyConfig *config,
} }
PyPreConfig preconfig; PyPreConfig preconfig;
preconfig.struct_size = sizeof(PyPreConfig);
status = _PyPreConfig_InitFromConfig(&preconfig, config); _PyPreConfig_InitFromConfig(&preconfig, config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (!config->parse_argv) { if (!config->parse_argv) {
return Py_PreInitialize(&preconfig); return Py_PreInitialize(&preconfig);
@ -852,7 +847,6 @@ pyinit_core(_PyRuntimeState *runtime,
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config); status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
@ -1079,7 +1073,6 @@ Py_InitializeEx(int install_sigs)
} }
PyConfig config; PyConfig config;
config.struct_size = sizeof(PyConfig);
status = _PyConfig_InitCompatConfig(&config); status = _PyConfig_InitCompatConfig(&config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {

View File

@ -61,11 +61,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
_PyGC_Initialize(&runtime->gc); _PyGC_Initialize(&runtime->gc);
_PyEval_Initialize(&runtime->ceval); _PyEval_Initialize(&runtime->ceval);
runtime->preconfig.struct_size = sizeof(PyPreConfig); PyPreConfig_InitPythonConfig(&runtime->preconfig);
PyStatus status = PyPreConfig_InitPythonConfig(&runtime->preconfig);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
runtime->gilstate.check_enabled = 1; runtime->gilstate.check_enabled = 1;
@ -209,7 +205,6 @@ PyInterpreterState_New(void)
memset(interp, 0, sizeof(*interp)); memset(interp, 0, sizeof(*interp));
interp->id_refcount = -1; interp->id_refcount = -1;
interp->config.struct_size = sizeof(PyConfig);
PyStatus status = PyConfig_InitPythonConfig(&interp->config); PyStatus status = PyConfig_InitPythonConfig(&interp->config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
/* Don't report status to caller: PyConfig_InitPythonConfig() /* Don't report status to caller: PyConfig_InitPythonConfig()