mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +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
|
@ -2770,7 +2770,7 @@ _PyBuiltin_Init(PyThreadState *tstate)
|
|||
{
|
||||
PyObject *mod, *dict, *debug;
|
||||
|
||||
const PyConfig *config = &tstate->interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
|
||||
if (PyType_Ready(&PyFilter_Type) < 0 ||
|
||||
PyType_Ready(&PyMap_Type) < 0 ||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
#include "Python.h"
|
||||
|
||||
#include "pycore_pystate.h" /* _PyInterpreterState_GET_UNSAFE() */
|
||||
#include "Python-ast.h"
|
||||
#include "ast.h"
|
||||
#include "code.h"
|
||||
|
@ -323,7 +322,6 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
|
|||
PyCodeObject *co = NULL;
|
||||
PyCompilerFlags local_flags = _PyCompilerFlags_INIT;
|
||||
int merged;
|
||||
PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
|
||||
|
||||
if (!__doc__) {
|
||||
__doc__ = PyUnicode_InternFromString("__doc__");
|
||||
|
@ -350,7 +348,7 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
|
|||
c.c_future->ff_features = merged;
|
||||
flags->cf_flags = merged;
|
||||
c.c_flags = flags;
|
||||
c.c_optimize = (optimize == -1) ? config->optimization_level : optimize;
|
||||
c.c_optimize = (optimize == -1) ? _Py_GetConfig()->optimization_level : optimize;
|
||||
c.c_nestlevel = 0;
|
||||
c.c_do_not_emit_bytecode = 0;
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "Python.h"
|
||||
#include "importdl.h"
|
||||
#include "pycore_pystate.h"
|
||||
|
||||
#if defined(__hp9000s300)
|
||||
#define FUNCNAME_PATTERN "_%.20s_%.200s"
|
||||
|
@ -21,7 +20,7 @@ dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
|
|||
const char *pathname, FILE *fp)
|
||||
{
|
||||
int flags = BIND_FIRST | BIND_DEFERRED;
|
||||
int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
|
||||
int verbose = _Py_GetConfig()->verbose;
|
||||
if (verbose) {
|
||||
flags = BIND_FIRST | BIND_IMMEDIATE |
|
||||
BIND_NONFATAL | BIND_VERBOSE;
|
||||
|
|
|
@ -102,7 +102,7 @@ _PyImportZip_Init(PyThreadState *tstate)
|
|||
goto error;
|
||||
}
|
||||
|
||||
int verbose = tstate->interp->config.verbose;
|
||||
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
|
||||
if (verbose) {
|
||||
PySys_WriteStderr("# installing zipimport hook\n");
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ _PyImport_Cleanup(PyThreadState *tstate)
|
|||
|
||||
/* XXX Perhaps these precautions are obsolete. Who knows? */
|
||||
|
||||
int verbose = interp->config.verbose;
|
||||
int verbose = _PyInterpreterState_GetConfig(interp)->verbose;
|
||||
if (verbose) {
|
||||
PySys_WriteStderr("# clear builtins._\n");
|
||||
}
|
||||
|
@ -811,7 +811,7 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int verbose = tstate->interp->config.verbose;
|
||||
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
|
||||
if (verbose) {
|
||||
PySys_FormatStderr("import %U # previously loaded (%R)\n",
|
||||
name, filename);
|
||||
|
@ -1523,7 +1523,7 @@ remove_importlib_frames(PyThreadState *tstate)
|
|||
which end with a call to "_call_with_frames_removed". */
|
||||
|
||||
_PyErr_Fetch(tstate, &exception, &value, &base_tb);
|
||||
if (!exception || tstate->interp->config.verbose) {
|
||||
if (!exception || _PyInterpreterState_GetConfig(tstate->interp)->verbose) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -1727,7 +1727,7 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
|
|||
_Py_IDENTIFIER(_find_and_load);
|
||||
PyObject *mod = NULL;
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
int import_time = interp->config.import_time;
|
||||
int import_time = _PyInterpreterState_GetConfig(interp)->import_time;
|
||||
static int import_level;
|
||||
static _PyTime_t accumulated;
|
||||
|
||||
|
@ -2413,7 +2413,7 @@ PyInit__imp(void)
|
|||
goto failure;
|
||||
}
|
||||
|
||||
const wchar_t *mode = _PyInterpreterState_GET_UNSAFE()->config.check_hash_pycs_mode;
|
||||
const wchar_t *mode = _Py_GetConfig()->check_hash_pycs_mode;
|
||||
PyObject *pyc_mode = PyUnicode_FromWideChar(mode, -1);
|
||||
if (pyc_mode == NULL) {
|
||||
goto failure;
|
||||
|
|
|
@ -2595,7 +2595,7 @@ _Py_GetConfigsAsDict(void)
|
|||
Py_CLEAR(dict);
|
||||
|
||||
/* core config */
|
||||
const PyConfig *config = &tstate->interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
dict = config_as_dict(config);
|
||||
if (dict == NULL) {
|
||||
goto error;
|
||||
|
@ -2662,7 +2662,7 @@ _Py_DumpPathConfig(PyThreadState *tstate)
|
|||
PySys_WriteStderr("\n"); \
|
||||
} while (0)
|
||||
|
||||
PyConfig *config = &tstate->interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
DUMP_CONFIG("PYTHONHOME", home);
|
||||
DUMP_CONFIG("PYTHONPATH", pythonpath_env);
|
||||
DUMP_CONFIG("program name", program_name);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -790,7 +790,7 @@ _PyInterpreterState_ClearModules(PyInterpreterState *interp)
|
|||
void
|
||||
PyThreadState_Clear(PyThreadState *tstate)
|
||||
{
|
||||
int verbose = tstate->interp->config.verbose;
|
||||
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
|
||||
|
||||
if (verbose && tstate->frame != NULL) {
|
||||
/* bpo-20526: After the main thread calls
|
||||
|
@ -1808,6 +1808,30 @@ _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp,
|
|||
interp->eval_frame = eval_frame;
|
||||
}
|
||||
|
||||
|
||||
const PyConfig*
|
||||
_PyInterpreterState_GetConfig(PyInterpreterState *interp)
|
||||
{
|
||||
return &interp->config;
|
||||
}
|
||||
|
||||
|
||||
PyStatus
|
||||
_PyInterpreterState_SetConfig(PyInterpreterState *interp,
|
||||
const PyConfig *config)
|
||||
{
|
||||
return _PyConfig_Copy(&interp->config, config);
|
||||
}
|
||||
|
||||
|
||||
const PyConfig*
|
||||
_Py_GetConfig(void)
|
||||
{
|
||||
assert(PyGILState_Check());
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
return _PyInterpreterState_GetConfig(tstate->interp);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -96,7 +96,7 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *
|
|||
PyCompilerFlags local_flags = _PyCompilerFlags_INIT;
|
||||
int nomem_count = 0;
|
||||
#ifdef Py_REF_DEBUG
|
||||
int show_ref_count = _PyInterpreterState_GET_UNSAFE()->config.show_ref_count;
|
||||
int show_ref_count = _Py_GetConfig()->show_ref_count;
|
||||
#endif
|
||||
|
||||
filename = PyUnicode_DecodeFSDefault(filename_str);
|
||||
|
@ -584,7 +584,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)
|
|||
int
|
||||
_Py_HandleSystemExit(int *exitcode_p)
|
||||
{
|
||||
int inspect = _PyInterpreterState_GET_UNSAFE()->config.inspect;
|
||||
int inspect = _Py_GetConfig()->inspect;
|
||||
if (inspect) {
|
||||
/* Don't exit if -i flag was given. This flag is set to 0
|
||||
* when entering interactive mode for inspecting. */
|
||||
|
|
|
@ -23,7 +23,6 @@ Data members:
|
|||
#include "pycore_pyerrors.h"
|
||||
#include "pycore_pylifecycle.h"
|
||||
#include "pycore_pymem.h"
|
||||
#include "pycore_pystate.h"
|
||||
#include "pycore_tupleobject.h"
|
||||
#include "pythread.h"
|
||||
#include "pydtrace.h"
|
||||
|
@ -337,7 +336,7 @@ _PySys_ClearAuditHooks(PyThreadState *ts)
|
|||
return;
|
||||
}
|
||||
|
||||
const PyConfig *config = &ts->interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(ts->interp);
|
||||
if (config->verbose) {
|
||||
PySys_WriteStderr("# clear sys.audit hooks\n");
|
||||
}
|
||||
|
@ -846,8 +845,8 @@ static PyObject *
|
|||
sys_getfilesystemencoding_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=1dc4bdbe9be44aa7 input=8475f8649b8c7d8c]*/
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
const PyConfig *config = &tstate->interp->config;
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
|
||||
return PyUnicode_FromWideChar(config->filesystem_encoding, -1);
|
||||
}
|
||||
|
||||
|
@ -861,8 +860,8 @@ static PyObject *
|
|||
sys_getfilesystemencodeerrors_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=ba77b36bbf7c96f5 input=22a1e8365566f1e5]*/
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
const PyConfig *config = &tstate->interp->config;
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
|
||||
return PyUnicode_FromWideChar(config->filesystem_errors, -1);
|
||||
}
|
||||
|
||||
|
@ -2455,7 +2454,7 @@ make_flags(PyThreadState *tstate)
|
|||
{
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
const PyPreConfig *preconfig = &interp->runtime->preconfig;
|
||||
const PyConfig *config = &interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
|
||||
|
||||
PyObject *seq = PyStructSequence_New(&FlagsType);
|
||||
if (seq == NULL) {
|
||||
|
@ -2889,7 +2888,7 @@ int
|
|||
_PySys_InitMain(PyThreadState *tstate)
|
||||
{
|
||||
PyObject *sysdict = tstate->interp->sysdict;
|
||||
const PyConfig *config = &tstate->interp->config;
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
int res;
|
||||
|
||||
#define COPY_LIST(KEY, VALUE) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue