@@ -551,62 +551,6 @@ pycore_init_runtime(_PyRuntimeState *runtime,
551551}
552552
553553
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-
610554static void
611555init_interp_create_gil (PyThreadState * tstate , int gil )
612556{
@@ -643,8 +587,15 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
643587 PyThreadState * * tstate_p )
644588{
645589 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+
646597 PyInterpreterState * interp ;
647- status = _PyInterpreterState_New (NULL , & interp );
598+ status = _PyInterpreterState_New (NULL , & config , & interp );
648599 if (_PyStatus_EXCEPTION (status )) {
649600 return status ;
650601 }
@@ -664,16 +615,6 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
664615 return status ;
665616 }
666617
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-
677618 // initialize the interp->obmalloc state. This must be done after
678619 // the settings are loaded (so that feature_flags are set) but before
679620 // any calls are made to obmalloc functions.
@@ -2253,18 +2194,19 @@ new_interpreter(PyThreadState **tstate_p,
22532194 interpreters: disable PyGILState_Check(). */
22542195 runtime -> gilstate .check_enabled = 0 ;
22552196
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 ;
22632197
22642198 // XXX Might new_interpreter() have been called without the GIL held?
22652199 PyThreadState * save_tstate = _PyThreadState_GET ();
22662200 PyThreadState * tstate = NULL ;
22672201
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+
22682210 /* From this point until the init_interp_create_gil() call,
22692211 we must not do anything that requires that the GIL be held
22702212 (or otherwise exist). That applies whether or not the new
@@ -2291,12 +2233,6 @@ new_interpreter(PyThreadState **tstate_p,
22912233 goto error ;
22922234 }
22932235
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-
23002236 // initialize the interp->obmalloc state. This must be done after
23012237 // the settings are loaded (so that feature_flags are set) but before
23022238 // any calls are made to obmalloc functions.
0 commit comments