summaryrefslogtreecommitdiffstats
path: root/Programs
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-09-28 02:28:35 (GMT)
committerGitHub <noreply@github.com>2019-09-28 02:28:35 (GMT)
commit441b10cf2855955c86565f8d59e72c2efc0f0a57 (patch)
treeba45fe16778b945069b5fa425ed769075171f95c /Programs
parent52d1b86bde2b772a76919c76991c326384954bf1 (diff)
downloadcpython-441b10cf2855955c86565f8d59e72c2efc0f0a57.zip
cpython-441b10cf2855955c86565f8d59e72c2efc0f0a57.tar.gz
cpython-441b10cf2855955c86565f8d59e72c2efc0f0a57.tar.bz2
bpo-38304: Add PyConfig.struct_size (GH-16451)
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.
Diffstat (limited to 'Programs')
-rw-r--r--Programs/_freeze_importlib.c1
-rw-r--r--Programs/_testembed.c121
2 files changed, 109 insertions, 13 deletions
diff --git a/Programs/_freeze_importlib.c b/Programs/_freeze_importlib.c
index 74735f2..7c494c2 100644
--- a/Programs/_freeze_importlib.c
+++ b/Programs/_freeze_importlib.c
@@ -78,6 +78,7 @@ 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 83c266b..a375945 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -385,7 +385,12 @@ static int check_init_compat_config(int preinit)
if (preinit) {
PyPreConfig preconfig;
- _PyPreConfig_InitCompatConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = _PyPreConfig_InitCompatConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
@@ -394,7 +399,13 @@ static int check_init_compat_config(int preinit)
}
PyConfig config;
- _PyConfig_InitCompatConfig(&config);
+ config.struct_size = sizeof(PyConfig);
+
+ status = _PyConfig_InitCompatConfig(&config);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
+
config_set_program_name(&config);
init_from_config_clear(&config);
@@ -470,7 +481,12 @@ static int test_init_from_config(void)
PyStatus status;
PyPreConfig preconfig;
- _PyPreConfig_InitCompatConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = _PyPreConfig_InitCompatConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
putenv("PYTHONMALLOC=malloc_debug");
preconfig.allocator = PYMEM_ALLOCATOR_MALLOC;
@@ -485,7 +501,12 @@ static int test_init_from_config(void)
}
PyConfig config;
- _PyConfig_InitCompatConfig(&config);
+ config.struct_size = sizeof(PyConfig);
+
+ status = _PyConfig_InitCompatConfig(&config);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
config.install_signal_handlers = 0;
/* FIXME: test use_environment */
@@ -617,6 +638,8 @@ 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)) {
Py_ExitStatusException(status);
@@ -702,6 +725,8 @@ 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)) {
Py_ExitStatusException(status);
@@ -755,6 +780,8 @@ 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)) {
Py_ExitStatusException(status);
@@ -779,7 +806,13 @@ static int test_preinit_isolated1(void)
PyStatus status;
PyPreConfig preconfig;
- _PyPreConfig_InitCompatConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = _PyPreConfig_InitCompatConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
+
preconfig.isolated = 1;
status = Py_PreInitialize(&preconfig);
@@ -788,7 +821,12 @@ static int test_preinit_isolated1(void)
}
PyConfig config;
- _PyConfig_InitCompatConfig(&config);
+ config.struct_size = sizeof(PyConfig);
+
+ status = _PyConfig_InitCompatConfig(&config);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
config_set_program_name(&config);
set_all_env_vars();
init_from_config_clear(&config);
@@ -805,7 +843,13 @@ static int test_preinit_isolated2(void)
PyStatus status;
PyPreConfig preconfig;
- _PyPreConfig_InitCompatConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = _PyPreConfig_InitCompatConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
+
preconfig.isolated = 0;
status = Py_PreInitialize(&preconfig);
@@ -815,7 +859,11 @@ static int test_preinit_isolated2(void)
/* Test PyConfig.isolated=1 */
PyConfig config;
- _PyConfig_InitCompatConfig(&config);
+ config.struct_size = sizeof(PyConfig);
+ status = _PyConfig_InitCompatConfig(&config);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
Py_IsolatedFlag = 0;
config.isolated = 1;
@@ -835,7 +883,12 @@ static int test_preinit_dont_parse_argv(void)
PyStatus status;
PyPreConfig preconfig;
- PyPreConfig_InitIsolatedConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = PyPreConfig_InitIsolatedConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
preconfig.isolated = 0;
@@ -852,6 +905,7 @@ static int test_preinit_dont_parse_argv(void)
}
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) {
@@ -877,6 +931,7 @@ static int test_preinit_parse_argv(void)
{
PyStatus status;
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
@@ -934,7 +989,12 @@ static int check_preinit_isolated_config(int preinit)
if (preinit) {
PyPreConfig preconfig;
- PyPreConfig_InitIsolatedConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = PyPreConfig_InitIsolatedConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
@@ -947,6 +1007,8 @@ static int check_preinit_isolated_config(int preinit)
}
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
+
status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
@@ -996,7 +1058,12 @@ static int check_init_python_config(int preinit)
if (preinit) {
PyPreConfig preconfig;
- PyPreConfig_InitPythonConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = PyPreConfig_InitPythonConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
@@ -1005,6 +1072,8 @@ static int check_init_python_config(int preinit)
}
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
+
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
@@ -1035,7 +1104,13 @@ static int test_init_dont_configure_locale(void)
PyStatus status;
PyPreConfig preconfig;
- PyPreConfig_InitPythonConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = PyPreConfig_InitPythonConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
+
preconfig.configure_locale = 0;
preconfig.coerce_c_locale = 1;
preconfig.coerce_c_locale_warn = 1;
@@ -1046,6 +1121,8 @@ static int test_init_dont_configure_locale(void)
}
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
+
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
@@ -1063,6 +1140,8 @@ static int test_init_dev_mode(void)
{
PyStatus status;
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
+
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
@@ -1286,6 +1365,8 @@ 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)) {
Py_ExitStatusException(status);
@@ -1334,6 +1415,8 @@ static int test_init_read_set(void)
{
PyStatus status;
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
+
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
@@ -1382,6 +1465,8 @@ 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);
if (PyStatus_Exception(status)) {
@@ -1450,7 +1535,12 @@ static int test_init_setpath_config(void)
{
PyStatus status;
PyPreConfig preconfig;
- PyPreConfig_InitPythonConfig(&preconfig);
+ preconfig.struct_size = sizeof(PyPreConfig);
+
+ status = PyPreConfig_InitPythonConfig(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
/* Explicitly preinitializes with Python preconfiguration to avoid
Py_SetPath() implicit preinitialization with compat preconfiguration. */
@@ -1474,6 +1564,7 @@ static int test_init_setpath_config(void)
putenv("TESTPATH=");
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
@@ -1531,6 +1622,8 @@ static int test_init_run_main(void)
{
PyStatus status;
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
+
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
@@ -1546,6 +1639,7 @@ static int test_init_main(void)
{
PyStatus status;
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
@@ -1577,6 +1671,7 @@ static int test_run_main(void)
{
PyStatus status;
PyConfig config;
+ config.struct_size = sizeof(PyConfig);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {