summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-03-18 08:26:25 (GMT)
committerGitHub <noreply@github.com>2020-03-18 08:26:25 (GMT)
commit56bfdebfb17ea9d3245b1f222e92b8e3b1ed6118 (patch)
tree69de990dd515d603b5fc01f172320b7b304fda12 /Python/pystate.c
parent611836a69a7a98bb106b4d315ed76a1e17266f4f (diff)
downloadcpython-56bfdebfb17ea9d3245b1f222e92b8e3b1ed6118.zip
cpython-56bfdebfb17ea9d3245b1f222e92b8e3b1ed6118.tar.gz
cpython-56bfdebfb17ea9d3245b1f222e92b8e3b1ed6118.tar.bz2
bpo-39984: Pass tstate to _PyEval_SignalAsyncExc() (GH-19049)
_PyEval_SignalAsyncExc() and _PyEval_FiniThreads() now expect tstate, instead of ceval.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index a349cea..a792cc5 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -1034,23 +1034,26 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
* head_mutex for the duration.
*/
HEAD_LOCK(runtime);
- for (PyThreadState *p = interp->tstate_head; p != NULL; p = p->next) {
- if (p->thread_id == id) {
- /* Tricky: we need to decref the current value
- * (if any) in p->async_exc, but that can in turn
- * allow arbitrary Python code to run, including
- * perhaps calls to this function. To prevent
- * deadlock, we need to release head_mutex before
- * the decref.
- */
- PyObject *old_exc = p->async_exc;
- Py_XINCREF(exc);
- p->async_exc = exc;
- HEAD_UNLOCK(runtime);
- Py_XDECREF(old_exc);
- _PyEval_SignalAsyncExc(&runtime->ceval);
- return 1;
+ for (PyThreadState *tstate = interp->tstate_head; tstate != NULL; tstate = tstate->next) {
+ if (tstate->thread_id != id) {
+ continue;
}
+
+ /* Tricky: we need to decref the current value
+ * (if any) in tstate->async_exc, but that can in turn
+ * allow arbitrary Python code to run, including
+ * perhaps calls to this function. To prevent
+ * deadlock, we need to release head_mutex before
+ * the decref.
+ */
+ PyObject *old_exc = tstate->async_exc;
+ Py_XINCREF(exc);
+ tstate->async_exc = exc;
+ HEAD_UNLOCK(runtime);
+
+ Py_XDECREF(old_exc);
+ _PyEval_SignalAsyncExc(tstate);
+ return 1;
}
HEAD_UNLOCK(runtime);
return 0;