bpo-36301: Cleanup preconfig code (GH-12535) · python/cpython@f72346c (original) (raw)
`@@ -1330,54 +1330,14 @@ config_init_fs_encoding(_PyCoreConfig *config)
`
1330
1330
`}
`
1331
1331
``
1332
1332
``
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
``
-
1373
1333
`/* Read the configuration into _PyCoreConfig from:
`
1374
1334
``
1375
1335
` * Environment variables
`
1376
1336
` * Py_xxx global configuration variables
`
1377
1337
``
1378
1338
` See _PyCoreConfig_ReadFromArgv() to parse also command line arguments. */
`
1379
1339
`_PyInitError
`
1380
``
`-
_PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig)
`
``
1340
`+
_PyCoreConfig_Read(_PyCoreConfig *config)
`
1381
1341
`{
`
1382
1342
`_PyInitError err;
`
1383
1343
``
`@@ -1386,25 +1346,12 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig)
`
1386
1346
`return err;
`
1387
1347
` }
`
1388
1348
``
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();
`
1392
1351
` }
`
1393
1352
``
1394
1353
`_PyCoreConfig_GetGlobalConfig(config);
`
1395
1354
``
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
``
-
1408
1355
`assert(config->preconfig.use_environment >= 0);
`
1409
1356
``
1410
1357
`if (config->preconfig.isolated > 0) {
`
`@@ -1548,11 +1495,22 @@ config_init_stdio(const _PyCoreConfig *config)
`
1548
1495
``
1549
1496
` - set Py_xxx global configuration variables
`
1550
1497
` - initialize C standard streams (stdin, stdout, stderr) */
`
1551
``
`-
void
`
``
1498
`+
_PyInitError
`
1552
1499
`_PyCoreConfig_Write(const _PyCoreConfig *config)
`
1553
1500
`{
`
1554
1501
`_PyCoreConfig_SetGlobalConfig(config);
`
1555
1502
`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();
`
1556
1514
`}
`
1557
1515
``
1558
1516
``
`@@ -2047,8 +2005,7 @@ config_usage(int error, const wchar_t* program)
`
2047
2005
``
2048
2006
`/* Parse command line options and environment variables. */
`
2049
2007
`static _PyInitError
`
2050
``
`-
config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
`
2051
``
`-
const _PyPreConfig *preconfig)
`
``
2008
`+
config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline)
`
2052
2009
`{
`
2053
2010
`int need_usage = 0;
`
2054
2011
`_PyInitError err;
`
`@@ -2067,7 +2024,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
`
2067
2024
`return err;
`
2068
2025
` }
`
2069
2026
``
2070
``
`-
_PyPreCmdline_SetPreConfig(&cmdline->precmdline, &config->preconfig);
`
``
2027
`+
_PyPreCmdline_SetPreConfig(&cmdline->precmdline, &_PyRuntime.preconfig);
`
2071
2028
`if (_PyWstrList_Extend(&config->xoptions, &cmdline->precmdline.xoptions) < 0) {
`
2072
2029
`return _Py_INIT_NO_MEMORY();
`
2073
2030
` }
`
`@@ -2098,7 +2055,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
`
2098
2055
`return err;
`
2099
2056
` }
`
2100
2057
``
2101
``
`-
err = _PyCoreConfig_Read(config, preconfig);
`
``
2058
`+
err = _PyCoreConfig_Read(config);
`
2102
2059
`if (_Py_INIT_FAILED(err)) {
`
2103
2060
`return err;
`
2104
2061
` }
`
`@@ -2129,8 +2086,7 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
`
2129
2086
` * Environment variables
`
2130
2087
` * Py_xxx global configuration variables */
`
2131
2088
`_PyInitError
`
2132
``
`-
_PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args,
`
2133
``
`-
const _PyPreConfig *preconfig)
`
``
2089
`+
_PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args)
`
2134
2090
`{
`
2135
2091
`_PyInitError err;
`
2136
2092
``
`@@ -2141,12 +2097,12 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args,
`
2141
2097
``
2142
2098
`_PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT};
`
2143
2099
``
2144
``
`-
err = _PyPreCmdline_Init(&cmdline.precmdline, args);
`
``
2100
`+
err = _PyPreCmdline_SetArgv(&cmdline.precmdline, args);
`
2145
2101
`if (_Py_INIT_FAILED(err)) {
`
2146
2102
` goto done;
`
2147
2103
` }
`
2148
2104
``
2149
``
`-
err = config_from_cmdline(config, &cmdline, preconfig);
`
``
2105
`+
err = config_from_cmdline(config, &cmdline);
`
2150
2106
`if (_Py_INIT_FAILED(err)) {
`
2151
2107
` goto done;
`
2152
2108
` }
`