@@ -1330,54 +1330,14 @@ config_init_fs_encoding(_PyCoreConfig *config)
13301330}
13311331
13321332
1333- static _PyInitError
1334- _PyCoreConfig_ReadPreConfig (_PyCoreConfig * config )
1335- {
1336- _PyInitError err ;
1337- _PyPreConfig local_preconfig = _PyPreConfig_INIT ;
1338- _PyPreConfig_GetGlobalConfig (& local_preconfig );
1339-
1340- if (_PyPreConfig_Copy (& local_preconfig , & config -> preconfig ) < 0 ) {
1341- err = _Py_INIT_NO_MEMORY ();
1342- goto done ;
1343- }
1344-
1345- err = _PyPreConfig_Read (& local_preconfig );
1346- if (_Py_INIT_FAILED (err )) {
1347- goto done ;
1348- }
1349-
1350- if (_PyPreConfig_Copy (& config -> preconfig , & local_preconfig ) < 0 ) {
1351- err = _Py_INIT_NO_MEMORY ();
1352- goto done ;
1353- }
1354- err = _Py_INIT_OK ();
1355-
1356- done :
1357- _PyPreConfig_Clear (& local_preconfig );
1358- return err ;
1359- }
1360-
1361-
1362- static _PyInitError
1363- _PyCoreConfig_GetPreConfig (_PyCoreConfig * config )
1364- {
1365- /* Read config written by _PyPreConfig_Write() */
1366- if (_PyPreConfig_Copy (& config -> preconfig , & _PyRuntime .preconfig ) < 0 ) {
1367- return _Py_INIT_NO_MEMORY ();
1368- }
1369- return _Py_INIT_OK ();
1370- }
1371-
1372-
13731333/* Read the configuration into _PyCoreConfig from:
13741334
13751335 * Environment variables
13761336 * Py_xxx global configuration variables
13771337
13781338 See _PyCoreConfig_ReadFromArgv() to parse also command line arguments. */
13791339_PyInitError
1380- _PyCoreConfig_Read (_PyCoreConfig * config , const _PyPreConfig * preconfig )
1340+ _PyCoreConfig_Read (_PyCoreConfig * config )
13811341{
13821342 _PyInitError err ;
13831343
@@ -1386,25 +1346,12 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig)
13861346 return err ;
13871347 }
13881348
1389- err = _PyCoreConfig_GetPreConfig (config );
1390- if (_Py_INIT_FAILED (err )) {
1391- return err ;
1349+ if (_PyPreConfig_Copy (& config -> preconfig , & _PyRuntime .preconfig ) < 0 ) {
1350+ return _Py_INIT_NO_MEMORY ();
13921351 }
13931352
13941353 _PyCoreConfig_GetGlobalConfig (config );
13951354
1396- if (preconfig != NULL ) {
1397- if (_PyPreConfig_Copy (& config -> preconfig , preconfig ) < 0 ) {
1398- return _Py_INIT_NO_MEMORY ();
1399- }
1400- }
1401- else {
1402- err = _PyCoreConfig_ReadPreConfig (config );
1403- if (_Py_INIT_FAILED (err )) {
1404- return err ;
1405- }
1406- }
1407-
14081355 assert (config -> preconfig .use_environment >= 0 );
14091356
14101357 if (config -> preconfig .isolated > 0 ) {
@@ -1548,11 +1495,22 @@ config_init_stdio(const _PyCoreConfig *config)
15481495
15491496 - set Py_xxx global configuration variables
15501497 - initialize C standard streams (stdin, stdout, stderr) */
1551- void
1498+ _PyInitError
15521499_PyCoreConfig_Write (const _PyCoreConfig * config )
15531500{
15541501 _PyCoreConfig_SetGlobalConfig (config );
15551502 config_init_stdio (config );
1503+
1504+ /* Write the new pre-configuration into _PyRuntime */
1505+ PyMemAllocatorEx old_alloc ;
1506+ _PyMem_SetDefaultAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
1507+ int res = _PyPreConfig_Copy (& _PyRuntime .preconfig , & config -> preconfig );
1508+ PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
1509+ if (res < 0 ) {
1510+ return _Py_INIT_NO_MEMORY ();
1511+ }
1512+
1513+ return _Py_INIT_OK ();
15561514}
15571515
15581516
@@ -2047,8 +2005,7 @@ config_usage(int error, const wchar_t* program)
20472005
20482006/* Parse command line options and environment variables. */
20492007static _PyInitError
2050- config_from_cmdline (_PyCoreConfig * config , _PyCmdline * cmdline ,
2051- const _PyPreConfig * preconfig )
2008+ config_from_cmdline (_PyCoreConfig * config , _PyCmdline * cmdline )
20522009{
20532010 int need_usage = 0 ;
20542011 _PyInitError err ;
@@ -2067,7 +2024,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
20672024 return err ;
20682025 }
20692026
2070- _PyPreCmdline_SetPreConfig (& cmdline -> precmdline , & config -> preconfig );
2027+ _PyPreCmdline_SetPreConfig (& cmdline -> precmdline , & _PyRuntime . preconfig );
20712028 if (_PyWstrList_Extend (& config -> xoptions , & cmdline -> precmdline .xoptions ) < 0 ) {
20722029 return _Py_INIT_NO_MEMORY ();
20732030 }
@@ -2098,7 +2055,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
20982055 return err ;
20992056 }
21002057
2101- err = _PyCoreConfig_Read (config , preconfig );
2058+ err = _PyCoreConfig_Read (config );
21022059 if (_Py_INIT_FAILED (err )) {
21032060 return err ;
21042061 }
@@ -2129,8 +2086,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
21292086 * Environment variables
21302087 * Py_xxx global configuration variables */
21312088_PyInitError
2132- _PyCoreConfig_ReadFromArgv (_PyCoreConfig * config , const _PyArgv * args ,
2133- const _PyPreConfig * preconfig )
2089+ _PyCoreConfig_ReadFromArgv (_PyCoreConfig * config , const _PyArgv * args )
21342090{
21352091 _PyInitError err ;
21362092
@@ -2141,12 +2097,12 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args,
21412097
21422098 _PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT };
21432099
2144- err = _PyPreCmdline_Init (& cmdline .precmdline , args );
2100+ err = _PyPreCmdline_SetArgv (& cmdline .precmdline , args );
21452101 if (_Py_INIT_FAILED (err )) {
21462102 goto done ;
21472103 }
21482104
2149- err = config_from_cmdline (config , & cmdline , preconfig );
2105+ err = config_from_cmdline (config , & cmdline );
21502106 if (_Py_INIT_FAILED (err )) {
21512107 goto done ;
21522108 }
0 commit comments