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

Original file line numberDiff line numberDiff line change

@@ -5,6 +5,7 @@

55

#include "pycore_getopt.h"

66

#include "pycore_pylifecycle.h"

77

#include "pycore_pymem.h"

8+

#include "pycore_pystate.h" /* _PyRuntime */

89

#include "pycore_pathconfig.h"

910

#include <locale.h> /* setlocale() */

1011

#ifdef HAVE_LANGINFO_H

@@ -1358,6 +1359,17 @@ _PyCoreConfig_ReadPreConfig(_PyCoreConfig *config)

13581359

}

13591360
13601361
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+
13611373

/* Read the configuration into _PyCoreConfig from:

13621374
13631375

* Environment variables

@@ -1374,6 +1386,11 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig)

13741386

return err;

13751387

}

13761388
1389+

err = _PyCoreConfig_GetPreConfig(config);

1390+

if (_Py_INIT_FAILED(err)) {

1391+

return err;

1392+

}

1393+
13771394

_PyCoreConfig_GetGlobalConfig(config);

13781395
13791396

if (preconfig != NULL) {

@@ -2117,6 +2134,11 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args,

21172134

{

21182135

_PyInitError err;

21192136
2137+

err = _Py_PreInitialize();

2138+

if (_Py_INIT_FAILED(err)) {

2139+

return err;

2140+

}

2141+
21202142

_PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT};

21212143
21222144

err = _PyPreCmdline_Init(&cmdline.precmdline, args);