mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-40268: Add _PyInterpreterState_GetConfig() (GH-19492)
Don't access PyInterpreterState.config member directly anymore, but use new functions: * _PyInterpreterState_GetConfig() * _PyInterpreterState_SetConfig() * _Py_GetConfig()
This commit is contained in:
parent
14d5331eb5
commit
da7933ecc3
19 changed files with 90 additions and 64 deletions
|
@ -157,7 +157,7 @@ init_importlib(PyThreadState *tstate, PyObject *sysmod)
|
|||
PyObject *impmod;
|
||||
PyObject *value;
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
int verbose = interp->config.verbose;
|
||||
int verbose = _PyInterpreterState_GetConfig(interp)->verbose;
|
||||
|
||||
/* Import _importlib through its frozen version, _frozen_importlib. */
|
||||
if (PyImport_ImportFrozenModule("_frozen_importlib") <= 0) {
|
||||
|
@ -473,11 +473,11 @@ pyinit_core_reconfigure(_PyRuntimeState *runtime,
|
|||
|
||||
_PyConfig_Write(config, runtime);
|
||||
|
||||
status = _PyConfig_Copy(&interp->config, config);
|
||||
status = _PyInterpreterState_SetConfig(interp, config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
config = &interp->config;
|
||||
config = _PyInterpreterState_GetConfig(interp);
|
||||
|
||||
if (config->_install_importlib) {
|
||||
status = _PyConfig_WritePathConfig(config);
|
||||
|
@ -558,7 +558,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
|
|||
return _PyStatus_ERR("can't make main interpreter");
|
||||
}
|
||||
|
||||
PyStatus status = _PyConfig_Copy(&interp->config, config);
|
||||
PyStatus status = _PyInterpreterState_SetConfig(interp, config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
@ -692,7 +692,7 @@ pycore_init_import_warnings(PyThreadState *tstate, PyObject *sysmod)
|
|||
return status;
|
||||
}
|
||||
|
||||
const PyConfig *config = &tstate->interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
if (_Py_IsMainInterpreter(tstate)) {
|
||||
/* Initialize _warnings. */
|
||||
status = _PyWarnings_InitState(tstate);
|
||||
|
@ -953,7 +953,7 @@ done:
|
|||
static PyStatus
|
||||
_Py_ReconfigureMainInterpreter(PyThreadState *tstate)
|
||||
{
|
||||
PyConfig *config = &tstate->interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
|
||||
PyObject *argv = _PyWideStringList_AsList(&config->argv);
|
||||
if (argv == NULL) {
|
||||
|
@ -977,7 +977,7 @@ init_interp_main(PyThreadState *tstate)
|
|||
PyStatus status;
|
||||
int is_main_interp = _Py_IsMainInterpreter(tstate);
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
PyConfig *config = &interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
|
||||
|
||||
if (!config->_install_importlib) {
|
||||
/* Special mode for freeze_importlib: run with no import system
|
||||
|
@ -1146,7 +1146,7 @@ Py_InitializeFromConfig(const PyConfig *config)
|
|||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
config = &tstate->interp->config;
|
||||
config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
|
||||
if (config->_init_main) {
|
||||
status = pyinit_main(tstate);
|
||||
|
@ -1571,16 +1571,16 @@ new_interpreter(PyThreadState **tstate_p)
|
|||
PyThreadState *save_tstate = PyThreadState_Swap(tstate);
|
||||
|
||||
/* Copy the current interpreter config into the new interpreter */
|
||||
PyConfig *config;
|
||||
const PyConfig *config;
|
||||
if (save_tstate != NULL) {
|
||||
config = &save_tstate->interp->config;
|
||||
config = _PyInterpreterState_GetConfig(save_tstate->interp);
|
||||
} else {
|
||||
/* No current thread state, copy from the main interpreter */
|
||||
PyInterpreterState *main_interp = PyInterpreterState_Main();
|
||||
config = &main_interp->config;
|
||||
config = _PyInterpreterState_GetConfig(main_interp);
|
||||
}
|
||||
|
||||
status = _PyConfig_Copy(&interp->config, config);
|
||||
status = _PyInterpreterState_SetConfig(interp, config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -1953,7 +1953,7 @@ init_sys_streams(PyThreadState *tstate)
|
|||
int fd;
|
||||
PyObject * encoding_attr;
|
||||
PyStatus res = _PyStatus_OK();
|
||||
const PyConfig *config = &tstate->interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
|
||||
/* Check that stdin is not a directory
|
||||
Using shell redirection, you can redirect stdin to a directory,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue