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.
This commit is contained in:
Victor Stinner 2018-08-03 15:33:52 +02:00 committed by GitHub
parent 2ebd3813af
commit caba55b3b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 107 additions and 93 deletions

View file

@ -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?