@@ -428,6 +428,67 @@ _Py_SetLocaleFromEnv(int category)
428
428
}
429
429
430
430
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
+
431
492
/* Global initializations. Can be undone by Py_Finalize(). Don't
432
493
call this twice without an intervening Py_Finalize() call.
433
494
@@ -462,7 +523,7 @@ pyinit_core_reconfigure(_PyRuntimeState *runtime,
462
523
return status ;
463
524
}
464
525
465
- status = _PyInterpreterState_SetConfig ( interp , config );
526
+ status = _PyConfig_Copy ( & interp -> config , config );
466
527
if (_PyStatus_EXCEPTION (status )) {
467
528
return status ;
468
529
}
@@ -550,7 +611,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
550
611
return _PyStatus_ERR ("can't make main interpreter" );
551
612
}
552
613
553
- PyStatus status = _PyInterpreterState_SetConfig ( interp , config );
614
+ PyStatus status = _PyConfig_Copy ( & interp -> config , config );
554
615
if (_PyStatus_EXCEPTION (status )) {
555
616
return status ;
556
617
}
@@ -917,7 +978,7 @@ pyinit_core(_PyRuntimeState *runtime,
917
978
}
918
979
919
980
PyConfig config ;
920
- _PyConfig_InitCompatConfig (& config );
981
+ PyConfig_InitPythonConfig (& config );
921
982
922
983
status = _PyConfig_Copy (& config , src_config );
923
984
if (_PyStatus_EXCEPTION (status )) {
@@ -1835,7 +1896,8 @@ new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
1835
1896
config = _PyInterpreterState_GetConfig (main_interp );
1836
1897
}
1837
1898
1838
- status = _PyInterpreterState_SetConfig (interp , config );
1899
+
1900
+ status = _PyConfig_Copy (& interp -> config , config );
1839
1901
if (_PyStatus_EXCEPTION (status )) {
1840
1902
goto error ;
1841
1903
}
0 commit comments