[Python-checkins] bpo-46417: _testembed.c avoids Py_SetProgramName() (GH-30732)
vstinner
webhook-mailer at python.org
Thu Jan 20 20:12:28 EST 2022
https://github.com/python/cpython/commit/6415e2ee4955b1a995c1e75544e2506b03780c3d
commit: 6415e2ee4955b1a995c1e75544e2506b03780c3d
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-01-21T02:12:18+01:00
summary:
bpo-46417: _testembed.c avoids Py_SetProgramName() (GH-30732)
* _testembed_Py_Initialize() now uses the PyConfig API, rather than
deprecated Py_SetProgramName().
* Reduce INIT_LOOPS from 16 to 4: test_embed now takes 8.7 seconds
rather than 14.7 seconds.
files:
M Lib/test/test_embed.py
M Programs/_testembed.c
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 204b194ed3bf3..19c53c392607b 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -32,7 +32,7 @@
# _PyCoreConfig_InitIsolatedConfig()
API_ISOLATED = 3
-INIT_LOOPS = 16
+INIT_LOOPS = 4
MAX_HASH_SEED = 4294967295
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 5bc0a127a8750..08e27d97723b3 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -30,7 +30,7 @@ char **main_argv;
/* Use path starting with "./" avoids a search along the PATH */
#define PROGRAM_NAME L"./_testembed"
-#define INIT_LOOPS 16
+#define INIT_LOOPS 4
// Ignore Py_DEPRECATED() compiler warnings: deprecated functions are
// tested on purpose here.
@@ -45,10 +45,39 @@ static void error(const char *msg)
}
+static void config_set_string(PyConfig *config, wchar_t **config_str, const wchar_t *str)
+{
+ PyStatus status = PyConfig_SetString(config, config_str, str);
+ if (PyStatus_Exception(status)) {
+ PyConfig_Clear(config);
+ Py_ExitStatusException(status);
+ }
+}
+
+
+static void config_set_program_name(PyConfig *config)
+{
+ const wchar_t *program_name = PROGRAM_NAME;
+ config_set_string(config, &config->program_name, program_name);
+}
+
+
+static void init_from_config_clear(PyConfig *config)
+{
+ PyStatus status = Py_InitializeFromConfig(config);
+ PyConfig_Clear(config);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
+}
+
+
static void _testembed_Py_Initialize(void)
{
- Py_SetProgramName(PROGRAM_NAME);
- Py_Initialize();
+ PyConfig config;
+ _PyConfig_InitCompatConfig(&config);
+ config_set_program_name(&config);
+ init_from_config_clear(&config);
}
@@ -391,16 +420,6 @@ static int test_init_initialize_config(void)
}
-static void config_set_string(PyConfig *config, wchar_t **config_str, const wchar_t *str)
-{
- PyStatus status = PyConfig_SetString(config, config_str, str);
- if (PyStatus_Exception(status)) {
- PyConfig_Clear(config);
- Py_ExitStatusException(status);
- }
-}
-
-
static void config_set_argv(PyConfig *config, Py_ssize_t argc, wchar_t * const *argv)
{
PyStatus status = PyConfig_SetArgv(config, argc, argv);
@@ -423,23 +442,6 @@ config_set_wide_string_list(PyConfig *config, PyWideStringList *list,
}
-static void config_set_program_name(PyConfig *config)
-{
- const wchar_t *program_name = PROGRAM_NAME;
- config_set_string(config, &config->program_name, program_name);
-}
-
-
-static void init_from_config_clear(PyConfig *config)
-{
- PyStatus status = Py_InitializeFromConfig(config);
- PyConfig_Clear(config);
- if (PyStatus_Exception(status)) {
- Py_ExitStatusException(status);
- }
-}
-
-
static int check_init_compat_config(int preinit)
{
PyStatus status;
More information about the Python-checkins
mailing list