Skip to content
Merged
Prev Previous commit
Next Next commit
Lock "HEAD" around looking up intepreter by ID.
  • Loading branch information
ericsnowcurrently committed Mar 8, 2019
commit 53d1e56c93bbe52a62e7920551c7ac791a4b4565
33 changes: 22 additions & 11 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,28 +314,39 @@ PyInterpreterState_GetID(PyInterpreterState *interp)
}


PyInterpreterState *
_PyInterpreterState_LookUpID(PY_INT64_T requested_id)
static PyInterpreterState *
interp_look_up_id(PY_INT64_T requested_id)
{
if (requested_id < 0)
goto error;

PyInterpreterState *interp = PyInterpreterState_Head();
while (interp != NULL) {
PY_INT64_T id = PyInterpreterState_GetID(interp);
if (id < 0)
if (id < 0) {
return NULL;
if (requested_id == id)
}
if (requested_id == id) {
return interp;
}
interp = PyInterpreterState_Next(interp);
}

error:
PyErr_Format(PyExc_RuntimeError,
"unrecognized interpreter ID %lld", requested_id);
return NULL;
}

PyInterpreterState *
_PyInterpreterState_LookUpID(PY_INT64_T requested_id)
{
PyInterpreterState *interp = NULL;
if (requested_id >= 0) {
HEAD_LOCK();
interp = interp_look_up_id(requested_id);
HEAD_UNLOCK();
}
if (interp == NULL && !PyErr_Occurred()) {
PyErr_Format(PyExc_RuntimeError,
"unrecognized interpreter ID %lld", requested_id);
}
return interp;
}


int
_PyInterpreterState_IDInitref(PyInterpreterState *interp)
Expand Down