bpo-34523: Use _PyCoreConfig instead of globals (GH-9005)
Use the core configuration of the interpreter, rather
than using global configuration variables. For example, replace
Py_QuietFlag with core_config->quiet.
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 91df4b0..58ea605 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -2076,7 +2076,7 @@
{
int pos = 0;
PyObject *seq;
- _PyCoreConfig *core_config = &_PyGILState_GetInterpreterStateUnsafe()->core_config;
+ const _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
seq = PyStructSequence_New(&FlagsType);
if (seq == NULL)
@@ -2085,23 +2085,23 @@
#define SetFlag(flag) \
PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag))
- SetFlag(Py_DebugFlag);
- SetFlag(Py_InspectFlag);
- SetFlag(Py_InteractiveFlag);
- SetFlag(Py_OptimizeFlag);
- SetFlag(Py_DontWriteBytecodeFlag);
- SetFlag(Py_NoUserSiteDirectory);
- SetFlag(Py_NoSiteFlag);
- SetFlag(Py_IgnoreEnvironmentFlag);
- SetFlag(Py_VerboseFlag);
+ SetFlag(config->parser_debug);
+ SetFlag(config->inspect);
+ SetFlag(config->interactive);
+ SetFlag(config->optimization_level);
+ SetFlag(!config->write_bytecode);
+ SetFlag(!config->user_site_directory);
+ SetFlag(!config->site_import);
+ SetFlag(!config->use_environment);
+ SetFlag(config->verbose);
/* SetFlag(saw_unbuffered_flag); */
/* SetFlag(skipfirstline); */
- SetFlag(Py_BytesWarningFlag);
- SetFlag(Py_QuietFlag);
- SetFlag(Py_HashRandomizationFlag);
- SetFlag(Py_IsolatedFlag);
- PyStructSequence_SET_ITEM(seq, pos++, PyBool_FromLong(core_config->dev_mode));
- SetFlag(Py_UTF8Mode);
+ SetFlag(config->bytes_warning);
+ SetFlag(config->quiet);
+ SetFlag(config->use_hash_seed == 0 || config->hash_seed != 0);
+ SetFlag(config->isolated);
+ PyStructSequence_SET_ITEM(seq, pos++, PyBool_FromLong(config->dev_mode));
+ SetFlag(config->utf8_mode);
#undef SetFlag
if (PyErr_Occurred()) {
@@ -2474,8 +2474,10 @@
} while (0)
int
-_PySys_EndInit(PyObject *sysdict, _PyMainInterpreterConfig *config)
+_PySys_EndInit(PyObject *sysdict, PyInterpreterState *interp)
{
+ const _PyCoreConfig *core_config = &interp->core_config;
+ const _PyMainInterpreterConfig *config = &interp->config;
int res;
/* _PyMainInterpreterConfig_Read() must set all these variables */
@@ -2523,7 +2525,7 @@
}
SET_SYS_FROM_STRING_INT_RESULT("dont_write_bytecode",
- PyBool_FromLong(Py_DontWriteBytecodeFlag));
+ PyBool_FromLong(!core_config->write_bytecode));
if (get_warnoptions() == NULL)
return -1;