@@ -506,8 +506,10 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
506
506
}
507
507
508
508
static int
509
- handle_signals (_PyRuntimeState * runtime )
509
+ handle_signals (PyThreadState * tstate )
510
510
{
511
+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
512
+
511
513
/* Only handle signals on main thread */
512
514
if (PyThread_get_thread_ident () != runtime -> main_thread ) {
513
515
return 0 ;
@@ -516,7 +518,7 @@ handle_signals(_PyRuntimeState *runtime)
516
518
* Ensure that the thread isn't currently running some other
517
519
* interpreter.
518
520
*/
519
- PyInterpreterState * interp = _PyRuntimeState_GetThreadState ( runtime ) -> interp ;
521
+ PyInterpreterState * interp = tstate -> interp ;
520
522
if (interp != runtime -> interpreters .main ) {
521
523
return 0 ;
522
524
}
@@ -531,10 +533,12 @@ handle_signals(_PyRuntimeState *runtime)
531
533
}
532
534
533
535
static int
534
- make_pending_calls (_PyRuntimeState * runtime )
536
+ make_pending_calls (PyThreadState * tstate )
535
537
{
536
538
static int busy = 0 ;
537
539
540
+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
541
+
538
542
/* only service pending calls on main thread */
539
543
if (PyThread_get_thread_ident () != runtime -> main_thread ) {
540
544
return 0 ;
@@ -586,8 +590,7 @@ _Py_FinishPendingCalls(PyThreadState *tstate)
586
590
{
587
591
assert (PyGILState_Check ());
588
592
589
- _PyRuntimeState * runtime = tstate -> interp -> runtime ;
590
- struct _pending_calls * pending = & runtime -> ceval .pending ;
593
+ struct _pending_calls * pending = & tstate -> interp -> runtime -> ceval .pending ;
591
594
592
595
PyThread_acquire_lock (pending -> lock , WAIT_LOCK );
593
596
pending -> finishing = 1 ;
@@ -597,7 +600,7 @@ _Py_FinishPendingCalls(PyThreadState *tstate)
597
600
return ;
598
601
}
599
602
600
- if (make_pending_calls (runtime ) < 0 ) {
603
+ if (make_pending_calls (tstate ) < 0 ) {
601
604
PyObject * exc , * val , * tb ;
602
605
_PyErr_Fetch (tstate , & exc , & val , & tb );
603
606
PyErr_BadInternalCall ();
@@ -613,15 +616,16 @@ Py_MakePendingCalls(void)
613
616
{
614
617
assert (PyGILState_Check ());
615
618
619
+ PyThreadState * tstate = _PyThreadState_GET ();
620
+
616
621
/* Python signal handler doesn't really queue a callback: it only signals
617
622
that a signal was received, see _PyEval_SignalReceived(). */
618
- _PyRuntimeState * runtime = & _PyRuntime ;
619
- int res = handle_signals (runtime );
623
+ int res = handle_signals (tstate );
620
624
if (res != 0 ) {
621
625
return res ;
622
626
}
623
627
624
- res = make_pending_calls (runtime );
628
+ res = make_pending_calls (tstate );
625
629
if (res != 0 ) {
626
630
return res ;
627
631
}
@@ -1231,12 +1235,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
1231
1235
}
1232
1236
1233
1237
if (_Py_atomic_load_relaxed (& ceval -> signals_pending )) {
1234
- if (handle_signals (runtime ) != 0 ) {
1238
+ if (handle_signals (tstate ) != 0 ) {
1235
1239
goto error ;
1236
1240
}
1237
1241
}
1238
1242
if (_Py_atomic_load_relaxed (& ceval -> pending .calls_to_do )) {
1239
- if (make_pending_calls (runtime ) != 0 ) {
1243
+ if (make_pending_calls (tstate ) != 0 ) {
1240
1244
goto error ;
1241
1245
}
1242
1246
}
0 commit comments