PyInterpreterState *interp,
_PyFrameEvalFunction eval_frame);
+PyAPI_FUNC(const PyConfig*) _PyInterpreterState_GetConfig(PyInterpreterState *interp);
+
+// Get the configuration of the currrent interpreter.
+// The caller must hold the GIL.
+PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
+
+
/* cross-interpreter data */
struct _xid;
/* Used by _PyImport_Cleanup() */
extern void _PyInterpreterState_ClearModules(PyInterpreterState *interp);
+extern PyStatus _PyInterpreterState_SetConfig(
+ PyInterpreterState *interp,
+ const PyConfig *config);
+
PyAPI_FUNC(void) _PyGILState_Reinit(_PyRuntimeState *runtime);
#define PY_SSIZE_T_CLEAN
#include "Python.h"
-#include "pycore_pystate.h" /* _PyInterpreterState_GET_UNSAFE() */
#include "structmember.h"
#include "_iomodule.h"
{
PyObject *RawIO_class = (PyObject *)&PyFileIO_Type;
#ifdef MS_WINDOWS
- PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
+ const PyConfig *config = _Py_GetConfig();
if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') {
RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type;
encoding = "utf-8";
shutdown issues). */
if (res == NULL) {
#ifndef Py_DEBUG
- const PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
- if (config->dev_mode) {
+ if (_Py_GetConfig()->dev_mode) {
PyErr_WriteUnraisable(self);
}
else {
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_object.h"
+#include "pycore_pystate.h"
#include "structmember.h"
#include "_iomodule.h"
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
#ifndef Py_DEBUG
/* In release mode, only check in development mode (-X dev) */
- if (!interp->config.dev_mode) {
+ if (!_PyInterpreterState_GetConfig(interp)->dev_mode) {
return 0;
}
#else
static int
-pymain_run_file(PyConfig *config, PyCompilerFlags *cf)
+pymain_run_file(const PyConfig *config, PyCompilerFlags *cf)
{
const wchar_t *filename = config->run_filename;
if (PySys_Audit("cpython.run_file", "u", filename) < 0) {
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
/* pymain_run_stdin() modify the config */
- PyConfig *config = &interp->config;
+ PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(interp);
PyObject *main_importer_path = NULL;
if (config->run_filename != NULL) {
#include "pycore_bytes_methods.h"
#include "pycore_object.h"
#include "pycore_pymem.h"
-#include "pycore_pystate.h"
#include "structmember.h"
#include "bytesobject.h"
#include "pystrhex.h"
static PyObject *
bytearray_str(PyObject *op)
{
- PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
- if (config->bytes_warning) {
+ if (_Py_GetConfig()->bytes_warning) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"str() on a bytearray instance", 1)) {
return NULL;
if (rc < 0)
return NULL;
if (rc) {
- PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
- if (config->bytes_warning && (op == Py_EQ || op == Py_NE)) {
+ if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"Comparison between bytearray and string", 1))
return NULL;
#include "pycore_bytes_methods.h"
#include "pycore_object.h"
#include "pycore_pymem.h"
-#include "pycore_pystate.h"
#include "pystrhex.h"
#include <stddef.h>
static PyObject *
bytes_str(PyObject *op)
{
- PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
- if (config->bytes_warning) {
+ if (_Py_GetConfig()->bytes_warning) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"str() on a bytes instance", 1)) {
return NULL;
/* Make sure both arguments are strings. */
if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
- PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
- if (config->bytes_warning && (op == Py_EQ || op == Py_NE)) {
+ if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) {
rc = PyObject_IsInstance((PyObject*)a,
(PyObject*)&PyUnicode_Type);
if (!rc)
Py_ssize_t pos;
PyObject *key, *value;
- int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
+ int verbose = _Py_GetConfig()->verbose;
/* First, clear only names starting with a single underscore */
pos = 0;
static void
module_dealloc(PyModuleObject *m)
{
- int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
+ int verbose = _Py_GetConfig()->verbose;
PyObject_GC_UnTrack(m);
if (verbose && m->md_name) {
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
#ifndef Py_DEBUG
/* In release mode, only check in development mode (-X dev) */
- if (!interp->config.dev_mode) {
+ if (!_PyInterpreterState_GetConfig(interp)->dev_mode) {
return 0;
}
#else
/* Before _PyUnicode_InitEncodings() is called, the Python codec
machinery is not ready and so cannot be used:
use wcstombs() in this case. */
- const wchar_t *filesystem_errors = interp->config.filesystem_errors;
+ const PyConfig *config = _PyInterpreterState_GetConfig(interp);
+ const wchar_t *filesystem_errors = config->filesystem_errors;
assert(filesystem_errors != NULL);
_Py_error_handler errors = get_error_handler_wide(filesystem_errors);
assert(errors != _Py_ERROR_UNKNOWN);
/* Before _PyUnicode_InitEncodings() is called, the Python codec
machinery is not ready and so cannot be used:
use mbstowcs() in this case. */
- const wchar_t *filesystem_errors = interp->config.filesystem_errors;
+ const PyConfig *config = _PyInterpreterState_GetConfig(interp);
+ const wchar_t *filesystem_errors = config->filesystem_errors;
assert(filesystem_errors != NULL);
_Py_error_handler errors = get_error_handler_wide(filesystem_errors);
assert(errors != _Py_ERROR_UNKNOWN);
init_stdio_encoding(PyThreadState *tstate)
{
/* Update the stdio encoding to the normalized Python codec name. */
- PyConfig *config = &tstate->interp->config;
+ PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(tstate->interp);
if (config_get_codec_name(&config->stdio_encoding) < 0) {
return _PyStatus_ERR("failed to get the Python codec name "
"of the stdio encoding");
static int
init_fs_codec(PyInterpreterState *interp)
{
- PyConfig *config = &interp->config;
+ const PyConfig *config = _PyInterpreterState_GetConfig(interp);
_Py_error_handler error_handler;
error_handler = get_error_handler_wide(config->filesystem_errors);
/* Update the filesystem encoding to the normalized Python codec name.
For example, replace "ANSI_X3.4-1968" (locale encoding) with "ascii"
(Python codec name). */
- PyConfig *config = &interp->config;
+ PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(interp);
if (config_get_codec_name(&config->filesystem_encoding) < 0) {
_Py_DumpPathConfig(tstate);
return _PyStatus_ERR("failed to get the Python codec "
_PyUnicode_EnableLegacyWindowsFSEncoding(void)
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
- PyConfig *config = &interp->config;
+ PyConfig *config = (PyConfig *)_PyInterpreterState_GetConfig(interp);
/* Set the filesystem encoding to mbcs/replace (PEP 529) */
wchar_t *encoding = _PyMem_RawWcsdup(L"mbcs");
{
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 ||
#include "Python.h"
-#include "pycore_pystate.h" /* _PyInterpreterState_GET_UNSAFE() */
#include "Python-ast.h"
#include "ast.h"
#include "code.h"
PyCodeObject *co = NULL;
PyCompilerFlags local_flags = _PyCompilerFlags_INIT;
int merged;
- PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (!__doc__) {
__doc__ = PyUnicode_InternFromString("__doc__");
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;
#include "Python.h"
#include "importdl.h"
-#include "pycore_pystate.h"
#if defined(__hp9000s300)
#define FUNCNAME_PATTERN "_%.20s_%.200s"
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;
goto error;
}
- int verbose = tstate->interp->config.verbose;
+ int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
if (verbose) {
PySys_WriteStderr("# installing zipimport hook\n");
}
/* 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");
}
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);
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;
}
_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;
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;
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;
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);
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) {
_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);
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;
}
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);
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) {
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
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- config = &tstate->interp->config;
+ config = _PyInterpreterState_GetConfig(tstate->interp);
if (config->_init_main) {
status = pyinit_main(tstate);
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;
}
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,
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
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
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);
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. */
#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"
return;
}
- const PyConfig *config = &ts->interp->config;
+ const PyConfig *config = _PyInterpreterState_GetConfig(ts->interp);
if (config->verbose) {
PySys_WriteStderr("# clear sys.audit hooks\n");
}
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);
}
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);
}
{
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) {
_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) \