bpo-36301: Add _PyRuntimeState.preconfig (GH-12506) · python/cpython@6d5ee97 (original) (raw)

Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
5 5 #include "pycore_getopt.h"
6 6 #include "pycore_pylifecycle.h"
7 7 #include "pycore_pymem.h"
8 +#include "pycore_pystate.h" /* _PyRuntime */
8 9 #include "pycore_pathconfig.h"
9 10 #include <locale.h> /* setlocale() */
10 11 #ifdef HAVE_LANGINFO_H
@@ -1358,6 +1359,17 @@ _PyCoreConfig_ReadPreConfig(_PyCoreConfig *config)
1358 1359 }
1359 1360
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 +
1361 1373 /* Read the configuration into _PyCoreConfig from:
1362 1374
1363 1375 * Environment variables
@@ -1374,6 +1386,11 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig)
1374 1386 return err;
1375 1387 }
1376 1388
1389 +err = _PyCoreConfig_GetPreConfig(config);
1390 +if (_Py_INIT_FAILED(err)) {
1391 +return err;
1392 + }
1393 +
1377 1394 _PyCoreConfig_GetGlobalConfig(config);
1378 1395
1379 1396 if (preconfig != NULL) {
@@ -2117,6 +2134,11 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args,
2117 2134 {
2118 2135 _PyInitError err;
2119 2136
2137 +err = _Py_PreInitialize();
2138 +if (_Py_INIT_FAILED(err)) {
2139 +return err;
2140 + }
2141 +
2120 2142 _PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT};
2121 2143
2122 2144 err = _PyPreCmdline_Init(&cmdline.precmdline, args);