diff options
author | Victor Stinner <vstinner@python.org> | 2019-11-20 01:27:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-20 01:27:56 (GMT) |
commit | 01b1cc12e7c6a3d6a3d27ba7c731687d57aae92a (patch) | |
tree | 1d1afefdc486c063853678d126975fe2d019059f /Python/sysmodule.c | |
parent | eb1cbbff1cd8214836a492502e75e463ade6f673 (diff) | |
download | cpython-01b1cc12e7c6a3d6a3d27ba7c731687d57aae92a.zip cpython-01b1cc12e7c6a3d6a3d27ba7c731687d57aae92a.tar.gz cpython-01b1cc12e7c6a3d6a3d27ba7c731687d57aae92a.tar.bz2 |
bpo-36710: Add PyInterpreterState.runtime field (GH-17270)
Add PyInterpreterState.runtime field: reference to the _PyRuntime
global variable. This field exists to not have to pass runtime in
addition to tstate to a function. Get runtime from tstate:
tstate->interp->runtime.
Remove "_PyRuntimeState *runtime" parameter from functions already
taking a "PyThreadState *tstate" parameter.
_PyGC_Init() first parameter becomes "PyThreadState *tstate".
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 9293540..30c7e98 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2387,17 +2387,18 @@ static PyStructSequence_Desc flags_desc = { }; static PyObject* -make_flags(_PyRuntimeState *runtime, PyThreadState *tstate) +make_flags(PyThreadState *tstate) { - int pos = 0; - PyObject *seq; - const PyPreConfig *preconfig = &runtime->preconfig; - const PyConfig *config = &tstate->interp->config; + PyInterpreterState *interp = tstate->interp; + const PyPreConfig *preconfig = &interp->runtime->preconfig; + const PyConfig *config = &interp->config; - seq = PyStructSequence_New(&FlagsType); - if (seq == NULL) + PyObject *seq = PyStructSequence_New(&FlagsType); + if (seq == NULL) { return NULL; + } + int pos = 0; #define SetFlag(flag) \ PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag)) @@ -2607,8 +2608,7 @@ static struct PyModuleDef sysmodule = { } while (0) static PyStatus -_PySys_InitCore(_PyRuntimeState *runtime, PyThreadState *tstate, - PyObject *sysdict) +_PySys_InitCore(PyThreadState *tstate, PyObject *sysdict) { PyObject *version_info; int res; @@ -2703,7 +2703,7 @@ _PySys_InitCore(_PyRuntimeState *runtime, PyThreadState *tstate, } } /* Set flags to their default values (updated by _PySys_InitMain()) */ - SET_SYS_FROM_STRING("flags", make_flags(runtime, tstate)); + SET_SYS_FROM_STRING("flags", make_flags(tstate)); #if defined(MS_WINDOWS) /* getwindowsversion */ @@ -2824,7 +2824,7 @@ sys_create_xoptions_dict(const PyConfig *config) int -_PySys_InitMain(_PyRuntimeState *runtime, PyThreadState *tstate) +_PySys_InitMain(PyThreadState *tstate) { PyObject *sysdict = tstate->interp->sysdict; const PyConfig *config = &tstate->interp->config; @@ -2879,7 +2879,7 @@ _PySys_InitMain(_PyRuntimeState *runtime, PyThreadState *tstate) #undef SET_SYS_FROM_WSTR /* Set flags to their final values */ - SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags(runtime, tstate)); + SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags(tstate)); /* prevent user from creating new instances */ FlagsType.tp_init = NULL; FlagsType.tp_new = NULL; @@ -2944,8 +2944,7 @@ error: /* Create sys module without all attributes: _PySys_InitMain() should be called later to add remaining attributes. */ PyStatus -_PySys_Create(_PyRuntimeState *runtime, PyThreadState *tstate, - PyObject **sysmod_p) +_PySys_Create(PyThreadState *tstate, PyObject **sysmod_p) { PyInterpreterState *interp = tstate->interp; @@ -2976,7 +2975,7 @@ _PySys_Create(_PyRuntimeState *runtime, PyThreadState *tstate, return status; } - status = _PySys_InitCore(runtime, tstate, sysdict); + status = _PySys_InitCore(tstate, sysdict); if (_PyStatus_EXCEPTION(status)) { return status; } |