@@ -428,6 +428,67 @@ _Py_SetLocaleFromEnv(int category)
428428}
429429
430430
431+ static int
432+ interpreter_set_config (const PyConfig * config )
433+ {
434+ PyThreadState * tstate = PyThreadState_Get ();
435+
436+ PyStatus status = _PyConfig_Write (config , tstate -> interp -> runtime );
437+ if (_PyStatus_EXCEPTION (status )) {
438+ _PyErr_SetFromPyStatus (status );
439+ return -1 ;
440+ }
441+
442+ status = _PyConfig_Copy (& tstate -> interp -> config , config );
443+ if (_PyStatus_EXCEPTION (status )) {
444+ _PyErr_SetFromPyStatus (status );
445+ return -1 ;
446+ }
447+ config = & tstate -> interp -> config ;
448+
449+ if (config -> _install_importlib && _Py_IsMainInterpreter (tstate )) {
450+ status = _PyConfig_WritePathConfig (config );
451+ if (_PyStatus_EXCEPTION (status )) {
452+ _PyErr_SetFromPyStatus (status );
453+ return -1 ;
454+ }
455+ }
456+
457+ // Update the sys module for the new configuration
458+ if (_PySys_UpdateConfig (tstate ) < 0 ) {
459+ return -1 ;
460+ }
461+ return 0 ;
462+ }
463+
464+
465+ int
466+ _PyInterpreterState_SetConfig (const PyConfig * src_config )
467+ {
468+ int res = -1 ;
469+
470+ PyConfig config ;
471+ PyConfig_InitPythonConfig (& config );
472+ PyStatus status = _PyConfig_Copy (& config , src_config );
473+ if (_PyStatus_EXCEPTION (status )) {
474+ _PyErr_SetFromPyStatus (status );
475+ goto done ;
476+ }
477+
478+ status = PyConfig_Read (& config );
479+ if (_PyStatus_EXCEPTION (status )) {
480+ _PyErr_SetFromPyStatus (status );
481+ goto done ;
482+ }
483+
484+ res = interpreter_set_config (& config );
485+
486+ done :
487+ PyConfig_Clear (& config );
488+ return res ;
489+ }
490+
491+
431492/* Global initializations. Can be undone by Py_Finalize(). Don't
432493 call this twice without an intervening Py_Finalize() call.
433494
@@ -462,7 +523,7 @@ pyinit_core_reconfigure(_PyRuntimeState *runtime,
462523 return status ;
463524 }
464525
465- status = _PyInterpreterState_SetConfig ( interp , config );
526+ status = _PyConfig_Copy ( & interp -> config , config );
466527 if (_PyStatus_EXCEPTION (status )) {
467528 return status ;
468529 }
@@ -550,7 +611,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
550611 return _PyStatus_ERR ("can't make main interpreter" );
551612 }
552613
553- PyStatus status = _PyInterpreterState_SetConfig ( interp , config );
614+ PyStatus status = _PyConfig_Copy ( & interp -> config , config );
554615 if (_PyStatus_EXCEPTION (status )) {
555616 return status ;
556617 }
@@ -917,7 +978,7 @@ pyinit_core(_PyRuntimeState *runtime,
917978 }
918979
919980 PyConfig config ;
920- _PyConfig_InitCompatConfig (& config );
981+ PyConfig_InitPythonConfig (& config );
921982
922983 status = _PyConfig_Copy (& config , src_config );
923984 if (_PyStatus_EXCEPTION (status )) {
@@ -1835,7 +1896,8 @@ new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
18351896 config = _PyInterpreterState_GetConfig (main_interp );
18361897 }
18371898
1838- status = _PyInterpreterState_SetConfig (interp , config );
1899+
1900+ status = _PyConfig_Copy (& interp -> config , config );
18391901 if (_PyStatus_EXCEPTION (status )) {
18401902 goto error ;
18411903 }
0 commit comments