Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
#endif

#include "cpython/coreconfig.h"
#include "pystate.h"
#include "pythread.h"

Expand Down Expand Up @@ -220,6 +221,7 @@ typedef struct pyruntimestate {
struct _ceval_runtime_state ceval;
struct _gilstate_runtime_state gilstate;

_PyPreConfig preconfig;
// XXX Consolidate globals found via the check-c-globals script.
} _PyRuntimeState;

Expand Down
10 changes: 10 additions & 0 deletions 10 Python/preconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,5 +839,15 @@ _PyPreConfig_Write(_PyPreConfig *config)
/* Set LC_CTYPE to the user preferred locale */
_Py_SetLocaleFromEnv(LC_CTYPE);

/* Write the new pre-configuration into _PyRuntime */
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
int res = _PyPreConfig_Copy(&_PyRuntime.preconfig, config);
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

if (res < 0) {
return _Py_INIT_NO_MEMORY();
}

return _Py_INIT_OK();
}
5 changes: 5 additions & 0 deletions 5 Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config,
return _Py_INIT_ERR("failed to copy core config");
}

/* Read config written by _PyPreConfig_Write() */
if (_PyPreConfig_Copy(&config->preconfig, &_PyRuntime.preconfig) < 0) {
return _Py_INIT_NO_MEMORY();
}

_PyInitError err = _PyCoreConfig_Read(config, NULL);
if (_Py_INIT_FAILED(err)) {
return err;
Expand Down
3 changes: 3 additions & 0 deletions 3 Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)

_PyGC_Initialize(&runtime->gc);
_PyEval_Initialize(&runtime->ceval);
runtime->preconfig = _PyPreConfig_INIT;

runtime->gilstate.check_enabled = 1;

Expand Down Expand Up @@ -92,6 +93,8 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime)
runtime->interpreters.mutex = NULL;
}

_PyPreConfig_Clear(&runtime->preconfig);

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.