mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-40082: trip_signal() uses the main interpreter (GH-19441)
Fix the signal handler: it now always uses the main interpreter, rather than trying to get the current Python thread state. The following function now accepts an interpreter, instead of a Python thread state: * _PyEval_SignalReceived() * _Py_ThreadCanHandleSignals() * _PyEval_AddPendingCall() * COMPUTE_EVAL_BREAKER() * SET_GIL_DROP_REQUEST(), RESET_GIL_DROP_REQUEST() * SIGNAL_PENDING_CALLS(), UNSIGNAL_PENDING_CALLS() * SIGNAL_PENDING_SIGNALS(), UNSIGNAL_PENDING_SIGNALS() * SIGNAL_ASYNC_EXC(), UNSIGNAL_ASYNC_EXC() Py_AddPendingCall() now uses the main interpreter if it fails to the current Python thread state. Convert _PyThreadState_GET() and PyInterpreterState_GET_UNSAFE() macros to static inline functions.
This commit is contained in:
parent
cfc3c2f8b3
commit
b54a99d643
6 changed files with 94 additions and 85 deletions
|
@ -19,9 +19,9 @@ extern void _Py_FinishPendingCalls(PyThreadState *tstate);
|
|||
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
|
||||
extern int _PyEval_InitState(struct _ceval_state *ceval);
|
||||
extern void _PyEval_FiniState(struct _ceval_state *ceval);
|
||||
PyAPI_FUNC(void) _PyEval_SignalReceived(PyThreadState *tstate);
|
||||
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
|
||||
PyAPI_FUNC(int) _PyEval_AddPendingCall(
|
||||
PyThreadState *tstate,
|
||||
PyInterpreterState *interp,
|
||||
int (*func)(void *),
|
||||
void *arg);
|
||||
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyThreadState *tstate);
|
||||
|
|
|
@ -310,9 +310,9 @@ _Py_IsMainInterpreter(PyThreadState* tstate)
|
|||
|
||||
/* Only handle signals on the main thread of the main interpreter. */
|
||||
static inline int
|
||||
_Py_ThreadCanHandleSignals(PyThreadState *tstate)
|
||||
_Py_ThreadCanHandleSignals(PyInterpreterState *interp)
|
||||
{
|
||||
return (_Py_IsMainThread() && _Py_IsMainInterpreter(tstate));
|
||||
return (_Py_IsMainThread() && interp == _PyRuntime.interpreters.main);
|
||||
}
|
||||
|
||||
|
||||
|
@ -340,7 +340,9 @@ static inline PyThreadState* _PyRuntimeState_GetThreadState(_PyRuntimeState *run
|
|||
The caller must hold the GIL.
|
||||
|
||||
See also PyThreadState_Get() and PyThreadState_GET(). */
|
||||
#define _PyThreadState_GET() _PyRuntimeState_GetThreadState(&_PyRuntime)
|
||||
static inline PyThreadState *_PyThreadState_GET(void) {
|
||||
return _PyRuntimeState_GetThreadState(&_PyRuntime);
|
||||
}
|
||||
|
||||
/* Redefine PyThreadState_GET() as an alias to _PyThreadState_GET() */
|
||||
#undef PyThreadState_GET
|
||||
|
@ -354,7 +356,10 @@ static inline PyThreadState* _PyRuntimeState_GetThreadState(_PyRuntimeState *run
|
|||
|
||||
See also _PyInterpreterState_Get()
|
||||
and _PyGILState_GetInterpreterStateUnsafe(). */
|
||||
#define _PyInterpreterState_GET_UNSAFE() (_PyThreadState_GET()->interp)
|
||||
static inline PyInterpreterState* _PyInterpreterState_GET_UNSAFE(void) {
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
return tstate->interp;
|
||||
}
|
||||
|
||||
|
||||
/* Other */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue