@@ -80,24 +80,18 @@ static void init_from_config_clear(PyConfig *config)
8080}
8181
8282
83- static void _testembed_Py_InitializeFromConfig (void )
83+ static void _testembed_initialize (void )
8484{
8585 PyConfig config ;
8686 _PyConfig_InitCompatConfig (& config );
8787 config_set_program_name (& config );
8888 init_from_config_clear (& config );
8989}
9090
91- static void _testembed_Py_Initialize (void )
92- {
93- Py_SetProgramName (PROGRAM_NAME );
94- Py_Initialize ();
95- }
96-
9791
9892static int test_import_in_subinterpreters (void )
9993{
100- _testembed_Py_InitializeFromConfig ();
94+ _testembed_initialize ();
10195 PyThreadState_Swap (Py_NewInterpreter ());
10296 return PyRun_SimpleString ("import readline" ); // gh-124160
10397}
@@ -131,7 +125,7 @@ static int test_repeated_init_and_subinterpreters(void)
131125
132126 for (int i = 1 ; i <= INIT_LOOPS ; i ++ ) {
133127 printf ("--- Pass %d ---\n" , i );
134- _testembed_Py_InitializeFromConfig ();
128+ _testembed_initialize ();
135129 mainstate = PyThreadState_Get ();
136130
137131 PyEval_ReleaseThread (mainstate );
@@ -197,7 +191,7 @@ static int test_repeated_init_exec(void)
197191 code = main_argv [i + 2 ];
198192 }
199193
200- _testembed_Py_InitializeFromConfig ();
194+ _testembed_initialize ();
201195 int err = PyRun_SimpleString (code );
202196 Py_Finalize ();
203197 if (err ) {
@@ -217,7 +211,7 @@ static int test_repeated_simple_init(void)
217211 fprintf (stderr , "--- Loop #%d ---\n" , i );
218212 fflush (stderr );
219213
220- _testembed_Py_Initialize ();
214+ _testembed_initialize ();
221215 Py_Finalize ();
222216 printf ("Finalized\n" ); // Give test_embed some output to check
223217 }
@@ -301,24 +295,8 @@ static int test_pre_initialization_api(void)
301295 /* the test doesn't support custom memory allocators */
302296 putenv ("PYTHONMALLOC=" );
303297
304- /* Leading "./" ensures getpath.c can still find the standard library */
305- _Py_EMBED_PREINIT_CHECK ("Checking Py_DecodeLocale\n" );
306- wchar_t * program = Py_DecodeLocale ("./spam" , NULL );
307- if (program == NULL ) {
308- fprintf (stderr , "Fatal error: cannot decode program name\n" );
309- return 1 ;
310- }
311- _Py_EMBED_PREINIT_CHECK ("Checking Py_SetProgramName\n" );
312- Py_SetProgramName (program );
313-
314- _Py_EMBED_PREINIT_CHECK ("Checking !Py_IsInitialized pre-initialization\n" );
315- if (Py_IsInitialized ()) {
316- fprintf (stderr , "Fatal error: initialized before initialization!\n" );
317- return 1 ;
318- }
319-
320298 _Py_EMBED_PREINIT_CHECK ("Initializing interpreter\n" );
321- Py_Initialize ();
299+ _testembed_initialize ();
322300
323301 _Py_EMBED_PREINIT_CHECK ("Checking Py_IsInitialized post-initialization\n" );
324302 if (!Py_IsInitialized ()) {
@@ -340,9 +318,6 @@ static int test_pre_initialization_api(void)
340318 fprintf (stderr , "Fatal error: still initialized after finalization!\n" );
341319 return 1 ;
342320 }
343-
344- _Py_EMBED_PREINIT_CHECK ("Freeing memory allocated by Py_DecodeLocale\n" );
345- PyMem_RawFree (program );
346321 return 0 ;
347322}
348323
@@ -367,8 +342,6 @@ static int test_pre_initialization_sys_options(void)
367342
368343 _Py_EMBED_PREINIT_CHECK ("Checking PySys_AddWarnOption\n" );
369344 PySys_AddWarnOption (L"default" );
370- _Py_EMBED_PREINIT_CHECK ("Checking PySys_ResetWarnOptions\n" );
371- PySys_ResetWarnOptions ();
372345 _Py_EMBED_PREINIT_CHECK ("Checking PySys_AddWarnOption linked list\n" );
373346 PySys_AddWarnOption (dynamic_once_warnoption );
374347 PySys_AddWarnOption (L"module" );
@@ -384,7 +357,7 @@ static int test_pre_initialization_sys_options(void)
384357 dynamic_xoption = NULL ;
385358
386359 _Py_EMBED_PREINIT_CHECK ("Initializing interpreter\n" );
387- _testembed_Py_InitializeFromConfig ();
360+ _testembed_initialize ();
388361 _Py_EMBED_PREINIT_CHECK ("Check sys module contents\n" );
389362 PyRun_SimpleString (
390363 "import sys; "
@@ -431,7 +404,7 @@ static int test_bpo20891(void)
431404 return 1 ;
432405 }
433406
434- _testembed_Py_InitializeFromConfig ();
407+ _testembed_initialize ();
435408
436409 unsigned long thrd = PyThread_start_new_thread (bpo20891_thread , & lock );
437410 if (thrd == PYTHREAD_INVALID_THREAD_ID ) {
@@ -454,7 +427,7 @@ static int test_bpo20891(void)
454427
455428static int test_initialize_twice (void )
456429{
457- _testembed_Py_InitializeFromConfig ();
430+ _testembed_initialize ();
458431
459432 /* bpo-33932: Calling Py_Initialize() twice should do nothing
460433 * (and not crash!). */
@@ -472,7 +445,7 @@ static int test_initialize_pymain(void)
472445 L"print(f'Py_Main() after Py_Initialize: "
473446 L"sys.argv={sys.argv}')" ),
474447 L"arg2" };
475- _testembed_Py_InitializeFromConfig ();
448+ _testembed_initialize ();
476449
477450 /* bpo-34008: Calling Py_Main() after Py_Initialize() must not crash */
478451 Py_Main (Py_ARRAY_LENGTH (argv ), argv );
@@ -495,7 +468,7 @@ dump_config(void)
495468
496469static int test_init_initialize_config (void )
497470{
498- _testembed_Py_InitializeFromConfig ();
471+ _testembed_initialize ();
499472 dump_config ();
500473 Py_Finalize ();
501474 return 0 ;
@@ -569,9 +542,6 @@ static int test_init_global_config(void)
569542 putenv ("PYTHONUTF8=0" );
570543 Py_UTF8Mode = 1 ;
571544
572- /* Test initialization from global configuration variables (Py_xxx) */
573- Py_SetProgramName (L"./globalvar" );
574-
575545 /* Py_IsolatedFlag is not tested */
576546 Py_NoSiteFlag = 1 ;
577547 Py_BytesWarningFlag = 1 ;
@@ -604,7 +574,7 @@ static int test_init_global_config(void)
604574 /* FIXME: test Py_LegacyWindowsFSEncodingFlag */
605575 /* FIXME: test Py_LegacyWindowsStdioFlag */
606576
607- Py_Initialize ();
577+ _testembed_initialize ();
608578 dump_config ();
609579 Py_Finalize ();
610580 return 0 ;
@@ -666,7 +636,6 @@ static int test_init_from_config(void)
666636 putenv ("PYTHONPYCACHEPREFIX=env_pycache_prefix" );
667637 config_set_string (& config , & config .pycache_prefix , L"conf_pycache_prefix" );
668638
669- Py_SetProgramName (L"./globalvar" );
670639 config_set_string (& config , & config .program_name , L"./conf_program_name" );
671640
672641 wchar_t * argv [] = {
@@ -853,7 +822,7 @@ static int test_init_compat_env(void)
853822 /* Test initialization from environment variables */
854823 Py_IgnoreEnvironmentFlag = 0 ;
855824 set_all_env_vars ();
856- _testembed_Py_InitializeFromConfig ();
825+ _testembed_initialize ();
857826 dump_config ();
858827 Py_Finalize ();
859828 return 0 ;
@@ -889,7 +858,7 @@ static int test_init_env_dev_mode(void)
889858 /* Test initialization from environment variables */
890859 Py_IgnoreEnvironmentFlag = 0 ;
891860 set_all_env_vars_dev_mode ();
892- _testembed_Py_InitializeFromConfig ();
861+ _testembed_initialize ();
893862 dump_config ();
894863 Py_Finalize ();
895864 return 0 ;
@@ -906,7 +875,7 @@ static int test_init_env_dev_mode_alloc(void)
906875#else
907876 putenv ("PYTHONMALLOC=mimalloc" );
908877#endif
909- _testembed_Py_InitializeFromConfig ();
878+ _testembed_initialize ();
910879 dump_config ();
911880 Py_Finalize ();
912881 return 0 ;
@@ -1246,7 +1215,7 @@ static int test_open_code_hook(void)
12461215 }
12471216
12481217 Py_IgnoreEnvironmentFlag = 0 ;
1249- _testembed_Py_InitializeFromConfig ();
1218+ _testembed_initialize ();
12501219 result = 0 ;
12511220
12521221 PyObject * r = PyFile_OpenCode ("$$test-filename" );
@@ -1310,7 +1279,7 @@ static int _test_audit(Py_ssize_t setValue)
13101279
13111280 Py_IgnoreEnvironmentFlag = 0 ;
13121281 PySys_AddAuditHook (_audit_hook , & sawSet );
1313- _testembed_Py_InitializeFromConfig ();
1282+ _testembed_initialize ();
13141283
13151284 if (PySys_Audit ("_testembed.raise" , NULL ) == 0 ) {
13161285 printf ("No error raised" );
@@ -1369,7 +1338,7 @@ static int test_audit_tuple(void)
13691338 // we need at least one hook, otherwise code checking for
13701339 // PySys_AuditTuple() is skipped.
13711340 PySys_AddAuditHook (_audit_hook , & sawSet );
1372- _testembed_Py_InitializeFromConfig ();
1341+ _testembed_initialize ();
13731342
13741343 ASSERT (!PyErr_Occurred (), 0 );
13751344
@@ -1422,7 +1391,7 @@ static int test_audit_subinterpreter(void)
14221391{
14231392 Py_IgnoreEnvironmentFlag = 0 ;
14241393 PySys_AddAuditHook (_audit_subinterpreter_hook , NULL );
1425- _testembed_Py_InitializeFromConfig ();
1394+ _testembed_initialize ();
14261395
14271396 Py_NewInterpreter ();
14281397 Py_NewInterpreter ();
@@ -2166,13 +2135,13 @@ static int test_unicode_id_init(void)
21662135 };
21672136
21682137 // Initialize Python once without using the identifier
2169- _testembed_Py_InitializeFromConfig ();
2138+ _testembed_initialize ();
21702139 Py_Finalize ();
21712140
21722141 // Now initialize Python multiple times and use the identifier.
21732142 // The first _PyUnicode_FromId() call initializes the identifier index.
21742143 for (int i = 0 ; i < 3 ; i ++ ) {
2175- _testembed_Py_InitializeFromConfig ();
2144+ _testembed_initialize ();
21762145
21772146 PyObject * str1 , * str2 ;
21782147
@@ -2195,7 +2164,7 @@ static int test_unicode_id_init(void)
21952164
21962165static int test_init_main_interpreter_settings (void )
21972166{
2198- _testembed_Py_Initialize ();
2167+ _testembed_initialize ();
21992168 (void ) PyRun_SimpleStringFlags (
22002169 "import _testinternalcapi, json; "
22012170 "print(json.dumps(_testinternalcapi.get_interp_settings(0)))" ,
@@ -2206,7 +2175,7 @@ static int test_init_main_interpreter_settings(void)
22062175
22072176static void do_init (void * unused )
22082177{
2209- _testembed_Py_Initialize ();
2178+ _testembed_initialize ();
22102179 Py_Finalize ();
22112180}
22122181
@@ -2331,7 +2300,7 @@ unwrap_allocator(PyMemAllocatorEx *allocator)
23312300static int
23322301test_get_incomplete_frame (void )
23332302{
2334- _testembed_Py_InitializeFromConfig ();
2303+ _testembed_initialize ();
23352304 PyMemAllocatorEx allocator ;
23362305 wrap_allocator (& allocator );
23372306 // Force an allocation with an incomplete (generator) frame:
0 commit comments