Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" (GH-13795)

This reverts commit 396e0a8d9d.
This commit is contained in:
Victor Stinner 2019-06-04 03:15:09 +02:00 committed by GitHub
parent 9535aff942
commit 0fd2c300c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 103 additions and 99 deletions

View file

@ -120,9 +120,8 @@ should_audit(void)
if (!ts) {
return 0;
}
PyInterpreterState *is = ts->interp;
_PyRuntimeState *runtime = is->runtime;
return runtime->audit_hook_head
PyInterpreterState *is = ts ? ts->interp : NULL;
return _PyRuntime.audit_hook_head
|| (is && is->audit_hooks)
|| PyDTrace_AUDIT_ENABLED();
}
@ -281,8 +280,8 @@ void _PySys_ClearAuditHooks(void) {
PySys_Audit("cpython._PySys_ClearAuditHooks", NULL);
PyErr_Clear();
_Py_AuditHookEntry *e = runtime->audit_hook_head, *n;
runtime->audit_hook_head = NULL;
_Py_AuditHookEntry *e = _PyRuntime.audit_hook_head, *n;
_PyRuntime.audit_hook_head = NULL;
while (e) {
n = e->next;
PyMem_RawFree(e);
@ -293,7 +292,6 @@ void _PySys_ClearAuditHooks(void) {
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()) {
@ -307,10 +305,10 @@ PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
}
}
_Py_AuditHookEntry *e = runtime->audit_hook_head;
_Py_AuditHookEntry *e = _PyRuntime.audit_hook_head;
if (!e) {
e = (_Py_AuditHookEntry*)PyMem_RawMalloc(sizeof(_Py_AuditHookEntry));
runtime->audit_hook_head = e;
_PyRuntime.audit_hook_head = e;
} else {
while (e->next)
e = e->next;
@ -2415,9 +2413,8 @@ static PyStructSequence_Desc flags_desc = {
};
static PyObject*
make_flags(PyInterpreterState *interp)
make_flags(_PyRuntimeState *runtime, PyInterpreterState *interp)
{
_PyRuntimeState *runtime = interp->runtime;
int pos = 0;
PyObject *seq;
const PyPreConfig *preconfig = &runtime->preconfig;
@ -2636,7 +2633,8 @@ static struct PyModuleDef sysmodule = {
} while (0)
static PyStatus
_PySys_InitCore(PyInterpreterState *interp, PyObject *sysdict)
_PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
PyObject *sysdict)
{
PyObject *version_info;
int res;
@ -2730,7 +2728,7 @@ _PySys_InitCore(PyInterpreterState *interp, PyObject *sysdict)
}
}
/* Set flags to their default values (updated by _PySys_InitMain()) */
SET_SYS_FROM_STRING("flags", make_flags(interp));
SET_SYS_FROM_STRING("flags", make_flags(runtime, interp));
#if defined(MS_WINDOWS)
/* getwindowsversion */
@ -2851,7 +2849,7 @@ sys_create_xoptions_dict(const PyConfig *config)
int
_PySys_InitMain(PyInterpreterState *interp)
_PySys_InitMain(_PyRuntimeState *runtime, PyInterpreterState *interp)
{
PyObject *sysdict = interp->sysdict;
const PyConfig *config = &interp->config;
@ -2905,7 +2903,7 @@ _PySys_InitMain(PyInterpreterState *interp)
#undef SET_SYS_FROM_WSTR
/* Set flags to their final values */
SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags(interp));
SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags(runtime, interp));
/* prevent user from creating new instances */
FlagsType.tp_init = NULL;
FlagsType.tp_new = NULL;
@ -2972,7 +2970,8 @@ error:
/* Create sys module without all attributes: _PySys_InitMain() should be called
later to add remaining attributes. */
PyStatus
_PySys_Create(PyInterpreterState *interp, PyObject **sysmod_p)
_PySys_Create(_PyRuntimeState *runtime, PyInterpreterState *interp,
PyObject **sysmod_p)
{
PyObject *modules = PyDict_New();
if (modules == NULL) {
@ -3001,7 +3000,7 @@ _PySys_Create(PyInterpreterState *interp, PyObject **sysmod_p)
return status;
}
status = _PySys_InitCore(interp, sysdict);
status = _PySys_InitCore(runtime, interp, sysdict);
if (_PyStatus_EXCEPTION(status)) {
return status;
}