@@ -456,26 +456,28 @@ _Py_SetLocaleFromEnv(int category)
456
456
457
457
458
458
static int
459
- interpreter_update_config ( PyThreadState * tstate , int only_update_path_config )
459
+ runtime_update_config ( _PyRuntimeState * runtime , int only_update_path_config )
460
460
{
461
- const PyConfig * config = & tstate -> interp -> global_config ;
462
-
463
461
if (!only_update_path_config ) {
464
- PyStatus status = _PyConfig_Write (config , tstate -> interp -> runtime );
462
+ PyStatus status = _PyConfig_Write (& runtime -> config , runtime );
465
463
if (_PyStatus_EXCEPTION (status )) {
466
464
_PyErr_SetFromPyStatus (status );
467
465
return -1 ;
468
466
}
469
467
}
470
468
471
- if (_Py_IsMainInterpreter (tstate -> interp )) {
472
- PyStatus status = _PyPathConfig_UpdateGlobal (config );
473
- if (_PyStatus_EXCEPTION (status )) {
474
- _PyErr_SetFromPyStatus (status );
475
- return -1 ;
476
- }
469
+ PyStatus status = _PyPathConfig_UpdateGlobal (& runtime -> config );
470
+ if (_PyStatus_EXCEPTION (status )) {
471
+ _PyErr_SetFromPyStatus (status );
472
+ return -1 ;
477
473
}
478
474
475
+ return 0 ;
476
+ }
477
+
478
+ static int
479
+ interpreter_update_config (PyThreadState * tstate )
480
+ {
479
481
// Update the sys module for the new configuration
480
482
if (_PySys_UpdateConfig (tstate ) < 0 ) {
481
483
return -1 ;
@@ -504,13 +506,20 @@ _Py_SetConfig(const PyConfig *src_config)
504
506
goto done ;
505
507
}
506
508
507
- status = _PyConfig_Copy (& tstate -> interp -> global_config , & config );
509
+ status = _PyConfig_Copy (& tstate -> interp -> runtime -> config , & config );
508
510
if (_PyStatus_EXCEPTION (status )) {
509
511
_PyErr_SetFromPyStatus (status );
510
512
goto done ;
511
513
}
512
514
513
- res = interpreter_update_config (tstate , 0 );
515
+ if (_Py_IsMainInterpreter (tstate -> interp )) {
516
+ res = runtime_update_config (tstate -> interp -> runtime , 0 );
517
+ if (res < 0 ) {
518
+ goto done ;
519
+ }
520
+ }
521
+
522
+ res = interpreter_update_config (tstate );
514
523
515
524
done :
516
525
PyConfig_Clear (& config );
@@ -546,13 +555,15 @@ pyinit_core_reconfigure(_PyRuntimeState *runtime,
546
555
if (interp == NULL ) {
547
556
return _PyStatus_ERR ("can't make main interpreter" );
548
557
}
558
+ assert (interp -> runtime == runtime );
559
+ assert (_Py_IsMainInterpreter (interp ));
549
560
550
561
status = _PyConfig_Write (config , runtime );
551
562
if (_PyStatus_EXCEPTION (status )) {
552
563
return status ;
553
564
}
554
565
555
- status = _PyConfig_Copy (& interp -> global_config , config );
566
+ status = _PyConfig_Copy (& runtime -> config , config );
556
567
if (_PyStatus_EXCEPTION (status )) {
557
568
return status ;
558
569
}
@@ -645,9 +656,10 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
645
656
if (interp == NULL ) {
646
657
return _PyStatus_ERR ("can't make main interpreter" );
647
658
}
659
+ assert (interp -> runtime == runtime );
648
660
assert (_Py_IsMainInterpreter (interp ));
649
661
650
- status = _PyConfig_Copy (& interp -> global_config , config );
662
+ status = _PyConfig_Copy (& runtime -> config , config );
651
663
if (_PyStatus_EXCEPTION (status )) {
652
664
return status ;
653
665
}
@@ -1067,7 +1079,12 @@ pyinit_core(_PyRuntimeState *runtime,
1067
1079
static PyStatus
1068
1080
pyinit_main_reconfigure (PyThreadState * tstate )
1069
1081
{
1070
- if (interpreter_update_config (tstate , 0 ) < 0 ) {
1082
+ if (_Py_IsMainInterpreter (tstate -> interp )) {
1083
+ if (runtime_update_config (tstate -> interp -> runtime , 0 ) < 0 ) {
1084
+ return _PyStatus_ERR ("fail to reconfigure Python" );
1085
+ }
1086
+ }
1087
+ if (interpreter_update_config (tstate ) < 0 ) {
1071
1088
return _PyStatus_ERR ("fail to reconfigure Python" );
1072
1089
}
1073
1090
return _PyStatus_OK ();
@@ -1098,13 +1115,18 @@ init_interp_main(PyThreadState *tstate)
1098
1115
return _PyStatus_OK ();
1099
1116
}
1100
1117
1101
- // Initialize the import-related configuration.
1102
- status = _PyConfig_InitImportConfig (& interp -> global_config );
1103
- if (_PyStatus_EXCEPTION (status )) {
1104
- return status ;
1105
- }
1118
+ if (is_main_interp ) {
1119
+ // Initialize the import-related configuration.
1120
+ status = _PyConfig_InitImportConfig (& interp -> runtime -> config );
1121
+ if (_PyStatus_EXCEPTION (status )) {
1122
+ return status ;
1123
+ }
1106
1124
1107
- if (interpreter_update_config (tstate , 1 ) < 0 ) {
1125
+ if (runtime_update_config (tstate -> interp -> runtime , 1 ) < 0 ) {
1126
+ return _PyStatus_ERR ("failed to update the Python config" );
1127
+ }
1128
+ }
1129
+ if (interpreter_update_config (tstate ) < 0 ) {
1108
1130
return _PyStatus_ERR ("failed to update the Python config" );
1109
1131
}
1110
1132
@@ -1766,14 +1788,14 @@ Py_FinalizeEx(void)
1766
1788
/* Copy the core config, PyInterpreterState_Delete() free
1767
1789
the core config memory */
1768
1790
#ifdef Py_REF_DEBUG
1769
- int show_ref_count = tstate -> interp -> global_config .show_ref_count ;
1791
+ int show_ref_count = runtime -> config .show_ref_count ;
1770
1792
#endif
1771
1793
#ifdef Py_TRACE_REFS
1772
- int dump_refs = tstate -> interp -> global_config .dump_refs ;
1773
- wchar_t * dump_refs_file = tstate -> interp -> global_config .dump_refs_file ;
1794
+ int dump_refs = runtime -> config .dump_refs ;
1795
+ wchar_t * dump_refs_file = runtime -> config .dump_refs_file ;
1774
1796
#endif
1775
1797
#ifdef WITH_PYMALLOC
1776
- int malloc_stats = tstate -> interp -> global_config .malloc_stats ;
1798
+ int malloc_stats = runtime -> config .malloc_stats ;
1777
1799
#endif
1778
1800
1779
1801
/* Remaining daemon threads will automatically exit
@@ -1972,27 +1994,18 @@ new_interpreter(PyThreadState **tstate_p, const _PyInterpreterConfig *config)
1972
1994
PyThreadState * save_tstate = PyThreadState_Swap (tstate );
1973
1995
1974
1996
/* Copy the current interpreter config into the new interpreter */
1975
- const PyConfig * global_config ;
1976
1997
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
1977
1998
if (save_tstate != NULL ) {
1978
- global_config = _PyInterpreterState_GetGlobalConfig (save_tstate -> interp );
1979
1999
if (config == NULL ) {
1980
2000
config = _PyInterpreterState_GetConfig (save_tstate -> interp );
1981
2001
}
1982
2002
}
1983
2003
else
1984
2004
#endif
1985
- {
2005
+ if ( config == NULL ) {
1986
2006
/* No current thread state, copy from the main interpreter */
1987
2007
PyInterpreterState * main_interp = _PyInterpreterState_Main ();
1988
- global_config = _PyInterpreterState_GetGlobalConfig (main_interp );
1989
- if (config == NULL ) {
1990
- config = _PyInterpreterState_GetConfig (main_interp );
1991
- }
1992
- }
1993
- status = _PyConfig_Copy (& interp -> global_config , global_config );
1994
- if (_PyStatus_EXCEPTION (status )) {
1995
- goto error ;
2008
+ config = _PyInterpreterState_GetConfig (main_interp );
1996
2009
}
1997
2010
status = _PyInterpreterConfig_Copy (& interp -> config , config );
1998
2011
if (_PyStatus_EXCEPTION (status )) {
0 commit comments