Skip to content

Commit d7fabc1

Browse files
authored
bpo-39984: Pass tstate to handle_signals() (GH-19050)
handle_signals() and make_pending_calls() now expect tstate rather than runtime.
1 parent 2fe815e commit d7fabc1

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Python/ceval.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,10 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
506506
}
507507

508508
static int
509-
handle_signals(_PyRuntimeState *runtime)
509+
handle_signals(PyThreadState *tstate)
510510
{
511+
_PyRuntimeState *runtime = tstate->interp->runtime;
512+
511513
/* Only handle signals on main thread */
512514
if (PyThread_get_thread_ident() != runtime->main_thread) {
513515
return 0;
@@ -516,7 +518,7 @@ handle_signals(_PyRuntimeState *runtime)
516518
* Ensure that the thread isn't currently running some other
517519
* interpreter.
518520
*/
519-
PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
521+
PyInterpreterState *interp = tstate->interp;
520522
if (interp != runtime->interpreters.main) {
521523
return 0;
522524
}
@@ -531,10 +533,12 @@ handle_signals(_PyRuntimeState *runtime)
531533
}
532534

533535
static int
534-
make_pending_calls(_PyRuntimeState *runtime)
536+
make_pending_calls(PyThreadState *tstate)
535537
{
536538
static int busy = 0;
537539

540+
_PyRuntimeState *runtime = tstate->interp->runtime;
541+
538542
/* only service pending calls on main thread */
539543
if (PyThread_get_thread_ident() != runtime->main_thread) {
540544
return 0;
@@ -586,8 +590,7 @@ _Py_FinishPendingCalls(PyThreadState *tstate)
586590
{
587591
assert(PyGILState_Check());
588592

589-
_PyRuntimeState *runtime = tstate->interp->runtime;
590-
struct _pending_calls *pending = &runtime->ceval.pending;
593+
struct _pending_calls *pending = &tstate->interp->runtime->ceval.pending;
591594

592595
PyThread_acquire_lock(pending->lock, WAIT_LOCK);
593596
pending->finishing = 1;
@@ -597,7 +600,7 @@ _Py_FinishPendingCalls(PyThreadState *tstate)
597600
return;
598601
}
599602

600-
if (make_pending_calls(runtime) < 0) {
603+
if (make_pending_calls(tstate) < 0) {
601604
PyObject *exc, *val, *tb;
602605
_PyErr_Fetch(tstate, &exc, &val, &tb);
603606
PyErr_BadInternalCall();
@@ -613,15 +616,16 @@ Py_MakePendingCalls(void)
613616
{
614617
assert(PyGILState_Check());
615618

619+
PyThreadState *tstate = _PyThreadState_GET();
620+
616621
/* Python signal handler doesn't really queue a callback: it only signals
617622
that a signal was received, see _PyEval_SignalReceived(). */
618-
_PyRuntimeState *runtime = &_PyRuntime;
619-
int res = handle_signals(runtime);
623+
int res = handle_signals(tstate);
620624
if (res != 0) {
621625
return res;
622626
}
623627

624-
res = make_pending_calls(runtime);
628+
res = make_pending_calls(tstate);
625629
if (res != 0) {
626630
return res;
627631
}
@@ -1231,12 +1235,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
12311235
}
12321236

12331237
if (_Py_atomic_load_relaxed(&ceval->signals_pending)) {
1234-
if (handle_signals(runtime) != 0) {
1238+
if (handle_signals(tstate) != 0) {
12351239
goto error;
12361240
}
12371241
}
12381242
if (_Py_atomic_load_relaxed(&ceval->pending.calls_to_do)) {
1239-
if (make_pending_calls(runtime) != 0) {
1243+
if (make_pending_calls(tstate) != 0) {
12401244
goto error;
12411245
}
12421246
}

0 commit comments

Comments
 (0)