bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)
https://bugs.python.org/issue36818
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 12b1bd7..97bff94 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -120,8 +120,9 @@
if (!ts) {
return 0;
}
- PyInterpreterState *is = ts ? ts->interp : NULL;
- return _PyRuntime.audit_hook_head
+ PyInterpreterState *is = ts->interp;
+ _PyRuntimeState *runtime = is->runtime;
+ return runtime->audit_hook_head
|| (is && is->audit_hooks)
|| PyDTrace_AUDIT_ENABLED();
}
@@ -280,8 +281,8 @@
PySys_Audit("cpython._PySys_ClearAuditHooks", NULL);
PyErr_Clear();
- _Py_AuditHookEntry *e = _PyRuntime.audit_hook_head, *n;
- _PyRuntime.audit_hook_head = NULL;
+ _Py_AuditHookEntry *e = runtime->audit_hook_head, *n;
+ runtime->audit_hook_head = NULL;
while (e) {
n = e->next;
PyMem_RawFree(e);
@@ -292,6 +293,7 @@
int
PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
{
+ _PyRuntimeState *runtime = &_PyRuntime;
/* Invoke existing audit hooks to allow them an opportunity to abort. */
/* Cannot invoke hooks until we are initialized */
if (Py_IsInitialized()) {
@@ -305,10 +307,10 @@
}
}
- _Py_AuditHookEntry *e = _PyRuntime.audit_hook_head;
+ _Py_AuditHookEntry *e = runtime->audit_hook_head;
if (!e) {
e = (_Py_AuditHookEntry*)PyMem_RawMalloc(sizeof(_Py_AuditHookEntry));
- _PyRuntime.audit_hook_head = e;
+ runtime->audit_hook_head = e;
} else {
while (e->next)
e = e->next;
@@ -2413,8 +2415,9 @@
};
static PyObject*
-make_flags(_PyRuntimeState *runtime, PyInterpreterState *interp)
+make_flags(PyInterpreterState *interp)
{
+ _PyRuntimeState *runtime = interp->runtime;
int pos = 0;
PyObject *seq;
const PyPreConfig *preconfig = &runtime->preconfig;
@@ -2633,8 +2636,7 @@
} while (0)
static PyStatus
-_PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
- PyObject *sysdict)
+_PySys_InitCore(PyInterpreterState *interp, PyObject *sysdict)
{
PyObject *version_info;
int res;
@@ -2728,7 +2730,7 @@
}
}
/* Set flags to their default values (updated by _PySys_InitMain()) */
- SET_SYS_FROM_STRING("flags", make_flags(runtime, interp));
+ SET_SYS_FROM_STRING("flags", make_flags(interp));
#if defined(MS_WINDOWS)
/* getwindowsversion */
@@ -2849,7 +2851,7 @@
int
-_PySys_InitMain(_PyRuntimeState *runtime, PyInterpreterState *interp)
+_PySys_InitMain(PyInterpreterState *interp)
{
PyObject *sysdict = interp->sysdict;
const PyConfig *config = &interp->config;
@@ -2903,7 +2905,7 @@
#undef SET_SYS_FROM_WSTR
/* Set flags to their final values */
- SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags(runtime, interp));
+ SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags(interp));
/* prevent user from creating new instances */
FlagsType.tp_init = NULL;
FlagsType.tp_new = NULL;
@@ -2970,8 +2972,7 @@
/* Create sys module without all attributes: _PySys_InitMain() should be called
later to add remaining attributes. */
PyStatus
-_PySys_Create(_PyRuntimeState *runtime, PyInterpreterState *interp,
- PyObject **sysmod_p)
+_PySys_Create(PyInterpreterState *interp, PyObject **sysmod_p)
{
PyObject *modules = PyDict_New();
if (modules == NULL) {
@@ -3000,7 +3001,7 @@
return status;
}
- status = _PySys_InitCore(runtime, interp, sysdict);
+ status = _PySys_InitCore(interp, sysdict);
if (_PyStatus_EXCEPTION(status)) {
return status;
}