mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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:
parent
94e165096f
commit
3c30a76f3d
14 changed files with 39 additions and 273 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue