@@ -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
@@ -384,7 +359,7 @@ static int test_pre_initialization_sys_options(void)
384
359
dynamic_xoption = NULL ;
385
360
386
361
_Py_EMBED_PREINIT_CHECK ("Initializing interpreter\n" );
387
- _testembed_Py_InitializeFromConfig ();
362
+ _testembed_initialize ();
388
363
_Py_EMBED_PREINIT_CHECK ("Check sys module contents\n" );
389
364
PyRun_SimpleString (
390
365
"import sys; "
@@ -431,7 +406,7 @@ static int test_bpo20891(void)
431
406
return 1 ;
432
407
}
433
408
434
- _testembed_Py_InitializeFromConfig ();
409
+ _testembed_initialize ();
435
410
436
411
unsigned long thrd = PyThread_start_new_thread (bpo20891_thread , & lock );
437
412
if (thrd == PYTHREAD_INVALID_THREAD_ID ) {
@@ -454,7 +429,7 @@ static int test_bpo20891(void)
454
429
455
430
static int test_initialize_twice (void )
456
431
{
457
- _testembed_Py_InitializeFromConfig ();
432
+ _testembed_initialize ();
458
433
459
434
/* bpo-33932: Calling Py_Initialize() twice should do nothing
460
435
* (and not crash!). */
@@ -472,7 +447,7 @@ static int test_initialize_pymain(void)
472
447
L"print(f'Py_Main() after Py_Initialize: "
473
448
L"sys.argv={sys.argv}')" ),
474
449
L"arg2" };
475
- _testembed_Py_InitializeFromConfig ();
450
+ _testembed_initialize ();
476
451
477
452
/* bpo-34008: Calling Py_Main() after Py_Initialize() must not crash */
478
453
Py_Main (Py_ARRAY_LENGTH (argv ), argv );
@@ -495,7 +470,7 @@ dump_config(void)
495
470
496
471
static int test_init_initialize_config (void )
497
472
{
498
- _testembed_Py_InitializeFromConfig ();
473
+ _testembed_initialize ();
499
474
dump_config ();
500
475
Py_Finalize ();
501
476
return 0 ;
@@ -569,9 +544,6 @@ static int test_init_global_config(void)
569
544
putenv ("PYTHONUTF8=0" );
570
545
Py_UTF8Mode = 1 ;
571
546
572
- /* Test initialization from global configuration variables (Py_xxx) */
573
- Py_SetProgramName (L"./globalvar" );
574
-
575
547
/* Py_IsolatedFlag is not tested */
576
548
Py_NoSiteFlag = 1 ;
577
549
Py_BytesWarningFlag = 1 ;
@@ -604,7 +576,7 @@ static int test_init_global_config(void)
604
576
/* FIXME: test Py_LegacyWindowsFSEncodingFlag */
605
577
/* FIXME: test Py_LegacyWindowsStdioFlag */
606
578
607
- Py_Initialize ();
579
+ _testembed_initialize ();
608
580
dump_config ();
609
581
Py_Finalize ();
610
582
return 0 ;
@@ -666,7 +638,6 @@ static int test_init_from_config(void)
666
638
putenv ("PYTHONPYCACHEPREFIX=env_pycache_prefix" );
667
639
config_set_string (& config , & config .pycache_prefix , L"conf_pycache_prefix" );
668
640
669
- Py_SetProgramName (L"./globalvar" );
670
641
config_set_string (& config , & config .program_name , L"./conf_program_name" );
671
642
672
643
wchar_t * argv [] = {
@@ -853,7 +824,7 @@ static int test_init_compat_env(void)
853
824
/* Test initialization from environment variables */
854
825
Py_IgnoreEnvironmentFlag = 0 ;
855
826
set_all_env_vars ();
856
- _testembed_Py_InitializeFromConfig ();
827
+ _testembed_initialize ();
857
828
dump_config ();
858
829
Py_Finalize ();
859
830
return 0 ;
@@ -889,7 +860,7 @@ static int test_init_env_dev_mode(void)
889
860
/* Test initialization from environment variables */
890
861
Py_IgnoreEnvironmentFlag = 0 ;
891
862
set_all_env_vars_dev_mode ();
892
- _testembed_Py_InitializeFromConfig ();
863
+ _testembed_initialize ();
893
864
dump_config ();
894
865
Py_Finalize ();
895
866
return 0 ;
@@ -906,7 +877,7 @@ static int test_init_env_dev_mode_alloc(void)
906
877
#else
907
878
putenv ("PYTHONMALLOC=mimalloc" );
908
879
#endif
909
- _testembed_Py_InitializeFromConfig ();
880
+ _testembed_initialize ();
910
881
dump_config ();
911
882
Py_Finalize ();
912
883
return 0 ;
@@ -1246,7 +1217,7 @@ static int test_open_code_hook(void)
1246
1217
}
1247
1218
1248
1219
Py_IgnoreEnvironmentFlag = 0 ;
1249
- _testembed_Py_InitializeFromConfig ();
1220
+ _testembed_initialize ();
1250
1221
result = 0 ;
1251
1222
1252
1223
PyObject * r = PyFile_OpenCode ("$$test-filename" );
@@ -1310,7 +1281,7 @@ static int _test_audit(Py_ssize_t setValue)
1310
1281
1311
1282
Py_IgnoreEnvironmentFlag = 0 ;
1312
1283
PySys_AddAuditHook (_audit_hook , & sawSet );
1313
- _testembed_Py_InitializeFromConfig ();
1284
+ _testembed_initialize ();
1314
1285
1315
1286
if (PySys_Audit ("_testembed.raise" , NULL ) == 0 ) {
1316
1287
printf ("No error raised" );
@@ -1369,7 +1340,7 @@ static int test_audit_tuple(void)
1369
1340
// we need at least one hook, otherwise code checking for
1370
1341
// PySys_AuditTuple() is skipped.
1371
1342
PySys_AddAuditHook (_audit_hook , & sawSet );
1372
- _testembed_Py_InitializeFromConfig ();
1343
+ _testembed_initialize ();
1373
1344
1374
1345
ASSERT (!PyErr_Occurred (), 0 );
1375
1346
@@ -1422,7 +1393,7 @@ static int test_audit_subinterpreter(void)
1422
1393
{
1423
1394
Py_IgnoreEnvironmentFlag = 0 ;
1424
1395
PySys_AddAuditHook (_audit_subinterpreter_hook , NULL );
1425
- _testembed_Py_InitializeFromConfig ();
1396
+ _testembed_initialize ();
1426
1397
1427
1398
Py_NewInterpreter ();
1428
1399
Py_NewInterpreter ();
@@ -2166,13 +2137,13 @@ static int test_unicode_id_init(void)
2166
2137
};
2167
2138
2168
2139
// Initialize Python once without using the identifier
2169
- _testembed_Py_InitializeFromConfig ();
2140
+ _testembed_initialize ();
2170
2141
Py_Finalize ();
2171
2142
2172
2143
// Now initialize Python multiple times and use the identifier.
2173
2144
// The first _PyUnicode_FromId() call initializes the identifier index.
2174
2145
for (int i = 0 ; i < 3 ; i ++ ) {
2175
- _testembed_Py_InitializeFromConfig ();
2146
+ _testembed_initialize ();
2176
2147
2177
2148
PyObject * str1 , * str2 ;
2178
2149
@@ -2195,7 +2166,7 @@ static int test_unicode_id_init(void)
2195
2166
2196
2167
static int test_init_main_interpreter_settings (void )
2197
2168
{
2198
- _testembed_Py_Initialize ();
2169
+ _testembed_initialize ();
2199
2170
(void ) PyRun_SimpleStringFlags (
2200
2171
"import _testinternalcapi, json; "
2201
2172
"print(json.dumps(_testinternalcapi.get_interp_settings(0)))" ,
@@ -2206,7 +2177,7 @@ static int test_init_main_interpreter_settings(void)
2206
2177
2207
2178
static void do_init (void * unused )
2208
2179
{
2209
- _testembed_Py_Initialize ();
2180
+ _testembed_initialize ();
2210
2181
Py_Finalize ();
2211
2182
}
2212
2183
@@ -2331,7 +2302,7 @@ unwrap_allocator(PyMemAllocatorEx *allocator)
2331
2302
static int
2332
2303
test_get_incomplete_frame (void )
2333
2304
{
2334
- _testembed_Py_InitializeFromConfig ();
2305
+ _testembed_initialize ();
2335
2306
PyMemAllocatorEx allocator ;
2336
2307
wrap_allocator (& allocator );
2337
2308
// Force an allocation with an incomplete (generator) frame:
0 commit comments