mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
e9e3eab0b8
commit
6415e2ee49
|
@ -32,7 +32,7 @@ API_PYTHON = 2
|
|||
# _PyCoreConfig_InitIsolatedConfig()
|
||||
API_ISOLATED = 3
|
||||
|
||||
INIT_LOOPS = 16
|
||||
INIT_LOOPS = 4
|
||||
MAX_HASH_SEED = 4294967295
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue