diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-08-03 15:33:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-03 15:33:52 +0200 |
commit | caba55b3b735405b280273f7d99866a046c18281 (patch) | |
tree | 3a98ac383b1fbab272158933255fb1a14107ebf6 /Python/pystate.c | |
parent | 2ebd3813af9172fe1f9b2f6004edf6f1e1e5d9f1 (diff) | |
download | cpython-git-caba55b3b735405b280273f7d99866a046c18281.tar.gz |
bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)
sys_setcheckinterval() now uses a local variable to parse arguments,
before writing into interp->check_interval.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index e8d390dfcf..7a4cd48077 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -264,6 +264,21 @@ PyInterpreterState_Delete(PyInterpreterState *interp) } +PyInterpreterState * +_PyInterpreterState_Get(void) +{ + PyThreadState *tstate = GET_TSTATE(); + if (tstate == NULL) { + Py_FatalError("_PyInterpreterState_Get(): no current thread state"); + } + PyInterpreterState *interp = tstate->interp; + if (interp == NULL) { + Py_FatalError("_PyInterpreterState_Get(): no current interpreter"); + } + return interp; +} + + int64_t PyInterpreterState_GetID(PyInterpreterState *interp) { @@ -1184,10 +1199,9 @@ _check_xidata(_PyCrossInterpreterData *data) int _PyObject_GetCrossInterpreterData(PyObject *obj, _PyCrossInterpreterData *data) { - PyThreadState *tstate = PyThreadState_Get(); - // PyThreadState_Get() aborts if lookup fails, so we don't need + // _PyInterpreterState_Get() aborts if lookup fails, so we don't need // to check the result for NULL. - PyInterpreterState *interp = tstate->interp; + PyInterpreterState *interp = _PyInterpreterState_Get(); // Reset data before re-populating. *data = (_PyCrossInterpreterData){0}; @@ -1235,7 +1249,7 @@ _call_in_interpreter(PyInterpreterState *interp, * naive approach. */ PyThreadState *save_tstate = NULL; - if (interp != PyThreadState_Get()->interp) { + if (interp != _PyInterpreterState_Get()) { // XXX Using the "head" thread isn't strictly correct. PyThreadState *tstate = PyInterpreterState_ThreadHead(interp); // XXX Possible GILState issues? |