@@ -80,24 +80,18 @@ static void init_from_config_clear(PyConfig *config)
80
80
}
81
81
82
82
83
- static void _testembed_Py_InitializeFromConfig (void )
83
+ static void _testembed_initialize (void )
84
84
{
85
85
PyConfig config ;
86
86
_PyConfig_InitCompatConfig (& config );
87
87
config_set_program_name (& config );
88
88
init_from_config_clear (& config );
89
89
}
90
90
91
- static void _testembed_Py_Initialize (void )
92
- {
93
- Py_SetProgramName (PROGRAM_NAME );
94
- Py_Initialize ();
95
- }
96
-
97
91
98
92
static int test_import_in_subinterpreters (void )
99
93
{
100
- _testembed_Py_InitializeFromConfig ();
94
+ _testembed_initialize ();
101
95
PyThreadState_Swap (Py_NewInterpreter ());
102
96
return PyRun_SimpleString ("import readline" ); // gh-124160
103
97
}
@@ -131,7 +125,7 @@ static int test_repeated_init_and_subinterpreters(void)
131
125
132
126
for (int i = 1 ; i <= INIT_LOOPS ; i ++ ) {
133
127
printf ("--- Pass %d ---\n" , i );
134
- _testembed_Py_InitializeFromConfig ();
128
+ _testembed_initialize ();
135
129
mainstate = PyThreadState_Get ();
136
130
137
131
PyEval_ReleaseThread (mainstate );
@@ -197,7 +191,7 @@ static int test_repeated_init_exec(void)
197
191
code = main_argv [i + 2 ];
198
192
}
199
193
200
- _testembed_Py_InitializeFromConfig ();
194
+ _testembed_initialize ();
201
195
int err = PyRun_SimpleString (code );
202
196
Py_Finalize ();
203
197
if (err ) {
@@ -217,7 +211,7 @@ static int test_repeated_simple_init(void)
217
211
fprintf (stderr , "--- Loop #%d ---\n" , i );
218
212
fflush (stderr );
219
213
220
- _testembed_Py_Initialize ();
214
+ _testembed_initialize ();
221
215
Py_Finalize ();
222
216
printf ("Finalized\n" ); // Give test_embed some output to check
223
217
}
@@ -301,24 +295,8 @@ static int test_pre_initialization_api(void)
301
295
/* the test doesn't support custom memory allocators */
302
296
putenv ("PYTHONMALLOC=" );
303
297
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
-
320
298
_Py_EMBED_PREINIT_CHECK ("Initializing interpreter\n" );
321
- Py_Initialize ();
299
+ _testembed_initialize ();
322
300
323
301
_Py_EMBED_PREINIT_CHECK ("Checking Py_IsInitialized post-initialization\n" );
324
302
if (!Py_IsInitialized ()) {
@@ -340,9 +318,6 @@ static int test_pre_initialization_api(void)
340
318
fprintf (stderr , "Fatal error: still initialized after finalization!\n" );
341
319
return 1 ;
342
320
}
343
-
344
- _Py_EMBED_PREINIT_CHECK ("Freeing memory allocated by Py_DecodeLocale\n" );
345
- PyMem_RawFree (program );
346
321
return 0 ;
347
322
}
348
323
@@ -367,8 +342,6 @@ static int test_pre_initialization_sys_options(void)
367
342
368
343
_Py_EMBED_PREINIT_CHECK ("Checking PySys_AddWarnOption\n" );
369
344
PySys_AddWarnOption (L"default" );
370
- _Py_EMBED_PREINIT_CHECK ("Checking PySys_ResetWarnOptions\n" );
371
- PySys_ResetWarnOptions ();
372
345
_Py_EMBED_PREINIT_CHECK ("Checking PySys_AddWarnOption linked list\n" );
373
346
PySys_AddWarnOption (dynamic_once_warnoption );
374
347
PySys_AddWarnOption (L"module" );
@@ -384,7 +357,7 @@ static int test_pre_initialization_sys_options(void)
384
357
dynamic_xoption = NULL ;
385
358
386
359
_Py_EMBED_PREINIT_CHECK ("Initializing interpreter\n" );
387
- _testembed_Py_InitializeFromConfig ();
360
+ _testembed_initialize ();
388
361
_Py_EMBED_PREINIT_CHECK ("Check sys module contents\n" );
389
362
PyRun_SimpleString (
390
363
"import sys; "
@@ -431,7 +404,7 @@ static int test_bpo20891(void)
431
404
return 1 ;
432
405
}
433
406
434
- _testembed_Py_InitializeFromConfig ();
407
+ _testembed_initialize ();
435
408
436
409
unsigned long thrd = PyThread_start_new_thread (bpo20891_thread , & lock );
437
410
if (thrd == PYTHREAD_INVALID_THREAD_ID ) {
@@ -454,7 +427,7 @@ static int test_bpo20891(void)
454
427
455
428
static int test_initialize_twice (void )
456
429
{
457
- _testembed_Py_InitializeFromConfig ();
430
+ _testembed_initialize ();
458
431
459
432
/* bpo-33932: Calling Py_Initialize() twice should do nothing
460
433
* (and not crash!). */
@@ -472,7 +445,7 @@ static int test_initialize_pymain(void)
472
445
L"print(f'Py_Main() after Py_Initialize: "
473
446
L"sys.argv={sys.argv}')" ),
474
447
L"arg2" };
475
- _testembed_Py_InitializeFromConfig ();
448
+ _testembed_initialize ();
476
449
477
450
/* bpo-34008: Calling Py_Main() after Py_Initialize() must not crash */
478
451
Py_Main (Py_ARRAY_LENGTH (argv ), argv );
@@ -495,7 +468,7 @@ dump_config(void)
495
468
496
469
static int test_init_initialize_config (void )
497
470
{
498
- _testembed_Py_InitializeFromConfig ();
471
+ _testembed_initialize ();
499
472
dump_config ();
500
473
Py_Finalize ();
501
474
return 0 ;
@@ -569,9 +542,6 @@ static int test_init_global_config(void)
569
542
putenv ("PYTHONUTF8=0" );
570
543
Py_UTF8Mode = 1 ;
571
544
572
- /* Test initialization from global configuration variables (Py_xxx) */
573
- Py_SetProgramName (L"./globalvar" );
574
-
575
545
/* Py_IsolatedFlag is not tested */
576
546
Py_NoSiteFlag = 1 ;
577
547
Py_BytesWarningFlag = 1 ;
@@ -604,7 +574,7 @@ static int test_init_global_config(void)
604
574
/* FIXME: test Py_LegacyWindowsFSEncodingFlag */
605
575
/* FIXME: test Py_LegacyWindowsStdioFlag */
606
576
607
- Py_Initialize ();
577
+ _testembed_initialize ();
608
578
dump_config ();
609
579
Py_Finalize ();
610
580
return 0 ;
@@ -666,7 +636,6 @@ static int test_init_from_config(void)
666
636
putenv ("PYTHONPYCACHEPREFIX=env_pycache_prefix" );
667
637
config_set_string (& config , & config .pycache_prefix , L"conf_pycache_prefix" );
668
638
669
- Py_SetProgramName (L"./globalvar" );
670
639
config_set_string (& config , & config .program_name , L"./conf_program_name" );
671
640
672
641
wchar_t * argv [] = {
@@ -853,7 +822,7 @@ static int test_init_compat_env(void)
853
822
/* Test initialization from environment variables */
854
823
Py_IgnoreEnvironmentFlag = 0 ;
855
824
set_all_env_vars ();
856
- _testembed_Py_InitializeFromConfig ();
825
+ _testembed_initialize ();
857
826
dump_config ();
858
827
Py_Finalize ();
859
828
return 0 ;
@@ -889,7 +858,7 @@ static int test_init_env_dev_mode(void)
889
858
/* Test initialization from environment variables */
890
859
Py_IgnoreEnvironmentFlag = 0 ;
891
860
set_all_env_vars_dev_mode ();
892
- _testembed_Py_InitializeFromConfig ();
861
+ _testembed_initialize ();
893
862
dump_config ();
894
863
Py_Finalize ();
895
864
return 0 ;
@@ -906,7 +875,7 @@ static int test_init_env_dev_mode_alloc(void)
906
875
#else
907
876
putenv ("PYTHONMALLOC=mimalloc" );
908
877
#endif
909
- _testembed_Py_InitializeFromConfig ();
878
+ _testembed_initialize ();
910
879
dump_config ();
911
880
Py_Finalize ();
912
881
return 0 ;
@@ -1246,7 +1215,7 @@ static int test_open_code_hook(void)
1246
1215
}
1247
1216
1248
1217
Py_IgnoreEnvironmentFlag = 0 ;
1249
- _testembed_Py_InitializeFromConfig ();
1218
+ _testembed_initialize ();
1250
1219
result = 0 ;
1251
1220
1252
1221
PyObject * r = PyFile_OpenCode ("$$test-filename" );
@@ -1310,7 +1279,7 @@ static int _test_audit(Py_ssize_t setValue)
1310
1279
1311
1280
Py_IgnoreEnvironmentFlag = 0 ;
1312
1281
PySys_AddAuditHook (_audit_hook , & sawSet );
1313
- _testembed_Py_InitializeFromConfig ();
1282
+ _testembed_initialize ();
1314
1283
1315
1284
if (PySys_Audit ("_testembed.raise" , NULL ) == 0 ) {
1316
1285
printf ("No error raised" );
@@ -1369,7 +1338,7 @@ static int test_audit_tuple(void)
1369
1338
// we need at least one hook, otherwise code checking for
1370
1339
// PySys_AuditTuple() is skipped.
1371
1340
PySys_AddAuditHook (_audit_hook , & sawSet );
1372
- _testembed_Py_InitializeFromConfig ();
1341
+ _testembed_initialize ();
1373
1342
1374
1343
ASSERT (!PyErr_Occurred (), 0 );
1375
1344
@@ -1422,7 +1391,7 @@ static int test_audit_subinterpreter(void)
1422
1391
{
1423
1392
Py_IgnoreEnvironmentFlag = 0 ;
1424
1393
PySys_AddAuditHook (_audit_subinterpreter_hook , NULL );
1425
- _testembed_Py_InitializeFromConfig ();
1394
+ _testembed_initialize ();
1426
1395
1427
1396
Py_NewInterpreter ();
1428
1397
Py_NewInterpreter ();
@@ -2166,13 +2135,13 @@ static int test_unicode_id_init(void)
2166
2135
};
2167
2136
2168
2137
// Initialize Python once without using the identifier
2169
- _testembed_Py_InitializeFromConfig ();
2138
+ _testembed_initialize ();
2170
2139
Py_Finalize ();
2171
2140
2172
2141
// Now initialize Python multiple times and use the identifier.
2173
2142
// The first _PyUnicode_FromId() call initializes the identifier index.
2174
2143
for (int i = 0 ; i < 3 ; i ++ ) {
2175
- _testembed_Py_InitializeFromConfig ();
2144
+ _testembed_initialize ();
2176
2145
2177
2146
PyObject * str1 , * str2 ;
2178
2147
@@ -2195,7 +2164,7 @@ static int test_unicode_id_init(void)
2195
2164
2196
2165
static int test_init_main_interpreter_settings (void )
2197
2166
{
2198
- _testembed_Py_Initialize ();
2167
+ _testembed_initialize ();
2199
2168
(void ) PyRun_SimpleStringFlags (
2200
2169
"import _testinternalcapi, json; "
2201
2170
"print(json.dumps(_testinternalcapi.get_interp_settings(0)))" ,
@@ -2206,7 +2175,7 @@ static int test_init_main_interpreter_settings(void)
2206
2175
2207
2176
static void do_init (void * unused )
2208
2177
{
2209
- _testembed_Py_Initialize ();
2178
+ _testembed_initialize ();
2210
2179
Py_Finalize ();
2211
2180
}
2212
2181
@@ -2331,7 +2300,7 @@ unwrap_allocator(PyMemAllocatorEx *allocator)
2331
2300
static int
2332
2301
test_get_incomplete_frame (void )
2333
2302
{
2334
- _testembed_Py_InitializeFromConfig ();
2303
+ _testembed_initialize ();
2335
2304
PyMemAllocatorEx allocator ;
2336
2305
wrap_allocator (& allocator );
2337
2306
// Force an allocation with an incomplete (generator) frame:
0 commit comments