bpo-38304: Add PyConfig.struct_size (GH-16451) (GH-16453)
Add a new struct_size field to PyPreConfig and PyConfig structures to
allow to modify these structures in the future without breaking the
backward compatibility.
* Replace private _config_version field with public struct_size field
in PyPreConfig and PyConfig.
* Public PyPreConfig_InitIsolatedConfig() and
PyPreConfig_InitPythonConfig()
return type becomes PyStatus, instead of void.
* Internal _PyConfig_InitCompatConfig(),
_PyPreConfig_InitCompatConfig(), _PyPreConfig_InitFromConfig(),
_PyPreConfig_InitFromPreConfig() return type becomes PyStatus,
instead of void.
* Remove _Py_CONFIG_VERSION
* Update the Initialization Configuration documentation.
(cherry picked from commit 441b10cf2855955c86565f8d59e72c2efc0f0a57)
diff --git a/Python/pystate.c b/Python/pystate.c
index f2924a8..f0662fa 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -60,7 +60,12 @@
_PyGC_Initialize(&runtime->gc);
_PyEval_Initialize(&runtime->ceval);
- PyPreConfig_InitPythonConfig(&runtime->preconfig);
+
+ runtime->preconfig.struct_size = sizeof(PyPreConfig);
+ PyStatus status = PyPreConfig_InitPythonConfig(&runtime->preconfig);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
runtime->gilstate.check_enabled = 1;
@@ -205,6 +210,7 @@
interp->id_refcount = -1;
interp->check_interval = 100;
+ interp->config.struct_size = sizeof(PyConfig);
PyStatus status = PyConfig_InitPythonConfig(&interp->config);
if (_PyStatus_EXCEPTION(status)) {
/* Don't report status to caller: PyConfig_InitPythonConfig()