@@ -551,62 +551,6 @@ pycore_init_runtime(_PyRuntimeState *runtime,
551
551
}
552
552
553
553
554
- static PyStatus
555
- init_interp_settings (PyInterpreterState * interp ,
556
- const PyInterpreterConfig * config )
557
- {
558
- assert (interp -> feature_flags == 0 );
559
-
560
- if (config -> use_main_obmalloc ) {
561
- interp -> feature_flags |= Py_RTFLAGS_USE_MAIN_OBMALLOC ;
562
- }
563
- else if (!config -> check_multi_interp_extensions ) {
564
- /* The reason: PyModuleDef.m_base.m_copy leaks objects between
565
- interpreters. */
566
- return _PyStatus_ERR ("per-interpreter obmalloc does not support "
567
- "single-phase init extension modules" );
568
- }
569
- #ifdef Py_GIL_DISABLED
570
- if (!_Py_IsMainInterpreter (interp ) &&
571
- !config -> check_multi_interp_extensions )
572
- {
573
- return _PyStatus_ERR ("The free-threaded build does not support "
574
- "single-phase init extension modules in "
575
- "subinterpreters" );
576
- }
577
- #endif
578
-
579
- if (config -> allow_fork ) {
580
- interp -> feature_flags |= Py_RTFLAGS_FORK ;
581
- }
582
- if (config -> allow_exec ) {
583
- interp -> feature_flags |= Py_RTFLAGS_EXEC ;
584
- }
585
- // Note that fork+exec is always allowed.
586
-
587
- if (config -> allow_threads ) {
588
- interp -> feature_flags |= Py_RTFLAGS_THREADS ;
589
- }
590
- if (config -> allow_daemon_threads ) {
591
- interp -> feature_flags |= Py_RTFLAGS_DAEMON_THREADS ;
592
- }
593
-
594
- if (config -> check_multi_interp_extensions ) {
595
- interp -> feature_flags |= Py_RTFLAGS_MULTI_INTERP_EXTENSIONS ;
596
- }
597
-
598
- switch (config -> gil ) {
599
- case PyInterpreterConfig_DEFAULT_GIL : break ;
600
- case PyInterpreterConfig_SHARED_GIL : break ;
601
- case PyInterpreterConfig_OWN_GIL : break ;
602
- default :
603
- return _PyStatus_ERR ("invalid interpreter config 'gil' value" );
604
- }
605
-
606
- return _PyStatus_OK ();
607
- }
608
-
609
-
610
554
static void
611
555
init_interp_create_gil (PyThreadState * tstate , int gil )
612
556
{
@@ -643,8 +587,15 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
643
587
PyThreadState * * tstate_p )
644
588
{
645
589
PyStatus status ;
590
+
591
+ PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT ;
592
+ // The main interpreter always has its own GIL and supports single-phase
593
+ // init extensions.
594
+ config .gil = PyInterpreterConfig_OWN_GIL ;
595
+ config .check_multi_interp_extensions = 0 ;
596
+
646
597
PyInterpreterState * interp ;
647
- status = _PyInterpreterState_New (NULL , & interp );
598
+ status = _PyInterpreterState_New (NULL , & config , & interp );
648
599
if (_PyStatus_EXCEPTION (status )) {
649
600
return status ;
650
601
}
@@ -664,16 +615,6 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
664
615
return status ;
665
616
}
666
617
667
- PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT ;
668
- // The main interpreter always has its own GIL and supports single-phase
669
- // init extensions.
670
- config .gil = PyInterpreterConfig_OWN_GIL ;
671
- config .check_multi_interp_extensions = 0 ;
672
- status = init_interp_settings (interp , & config );
673
- if (_PyStatus_EXCEPTION (status )) {
674
- return status ;
675
- }
676
-
677
618
// initialize the interp->obmalloc state. This must be done after
678
619
// the settings are loaded (so that feature_flags are set) but before
679
620
// any calls are made to obmalloc functions.
@@ -2253,18 +2194,19 @@ new_interpreter(PyThreadState **tstate_p,
2253
2194
interpreters: disable PyGILState_Check(). */
2254
2195
runtime -> gilstate .check_enabled = 0 ;
2255
2196
2256
- PyInterpreterState * interp = PyInterpreterState_New ();
2257
- if (interp == NULL ) {
2258
- * tstate_p = NULL ;
2259
- return _PyStatus_OK ();
2260
- }
2261
- _PyInterpreterState_SetWhence (interp , whence );
2262
- interp -> _ready = 1 ;
2263
2197
2264
2198
// XXX Might new_interpreter() have been called without the GIL held?
2265
2199
PyThreadState * save_tstate = _PyThreadState_GET ();
2266
2200
PyThreadState * tstate = NULL ;
2267
2201
2202
+ PyInterpreterState * interp ;
2203
+ status = _PyInterpreterState_New (save_tstate , config , & interp );
2204
+ if (_PyStatus_EXCEPTION (status )) {
2205
+ return status ;
2206
+ }
2207
+ _PyInterpreterState_SetWhence (interp , whence );
2208
+ interp -> _ready = 1 ;
2209
+
2268
2210
/* From this point until the init_interp_create_gil() call,
2269
2211
we must not do anything that requires that the GIL be held
2270
2212
(or otherwise exist). That applies whether or not the new
@@ -2291,12 +2233,6 @@ new_interpreter(PyThreadState **tstate_p,
2291
2233
goto error ;
2292
2234
}
2293
2235
2294
- /* This does not require that the GIL be held. */
2295
- status = init_interp_settings (interp , config );
2296
- if (_PyStatus_EXCEPTION (status )) {
2297
- goto error ;
2298
- }
2299
-
2300
2236
// initialize the interp->obmalloc state. This must be done after
2301
2237
// the settings are loaded (so that feature_flags are set) but before
2302
2238
// any calls are made to obmalloc functions.
0 commit comments