@@ -30,7 +30,7 @@ char **main_argv;
3030/* Use path starting with "./" avoids a search along the PATH */
3131#define PROGRAM_NAME L"./_testembed"
3232
33- #define INIT_LOOPS 16
33+ #define INIT_LOOPS 4
3434
3535// Ignore Py_DEPRECATED() compiler warnings: deprecated functions are
3636// tested on purpose here.
@@ -45,10 +45,39 @@ static void error(const char *msg)
4545}
4646
4747
48+ static void config_set_string (PyConfig * config , wchar_t * * config_str , const wchar_t * str )
49+ {
50+ PyStatus status = PyConfig_SetString (config , config_str , str );
51+ if (PyStatus_Exception (status )) {
52+ PyConfig_Clear (config );
53+ Py_ExitStatusException (status );
54+ }
55+ }
56+
57+
58+ static void config_set_program_name (PyConfig * config )
59+ {
60+ const wchar_t * program_name = PROGRAM_NAME ;
61+ config_set_string (config , & config -> program_name , program_name );
62+ }
63+
64+
65+ static void init_from_config_clear (PyConfig * config )
66+ {
67+ PyStatus status = Py_InitializeFromConfig (config );
68+ PyConfig_Clear (config );
69+ if (PyStatus_Exception (status )) {
70+ Py_ExitStatusException (status );
71+ }
72+ }
73+
74+
4875static void _testembed_Py_Initialize (void )
4976{
50- Py_SetProgramName (PROGRAM_NAME );
51- Py_Initialize ();
77+ PyConfig config ;
78+ _PyConfig_InitCompatConfig (& config );
79+ config_set_program_name (& config );
80+ init_from_config_clear (& config );
5281}
5382
5483
@@ -391,16 +420,6 @@ static int test_init_initialize_config(void)
391420}
392421
393422
394- static void config_set_string (PyConfig * config , wchar_t * * config_str , const wchar_t * str )
395- {
396- PyStatus status = PyConfig_SetString (config , config_str , str );
397- if (PyStatus_Exception (status )) {
398- PyConfig_Clear (config );
399- Py_ExitStatusException (status );
400- }
401- }
402-
403-
404423static void config_set_argv (PyConfig * config , Py_ssize_t argc , wchar_t * const * argv )
405424{
406425 PyStatus status = PyConfig_SetArgv (config , argc , argv );
@@ -423,23 +442,6 @@ config_set_wide_string_list(PyConfig *config, PyWideStringList *list,
423442}
424443
425444
426- static void config_set_program_name (PyConfig * config )
427- {
428- const wchar_t * program_name = PROGRAM_NAME ;
429- config_set_string (config , & config -> program_name , program_name );
430- }
431-
432-
433- static void init_from_config_clear (PyConfig * config )
434- {
435- PyStatus status = Py_InitializeFromConfig (config );
436- PyConfig_Clear (config );
437- if (PyStatus_Exception (status )) {
438- Py_ExitStatusException (status );
439- }
440- }
441-
442-
443445static int check_init_compat_config (int preinit )
444446{
445447 PyStatus status ;
0 commit comments