summaryrefslogtreecommitdiffstats
path: root/Include/internal
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-08 21:35:05 (GMT)
committerGitHub <noreply@github.com>2020-04-08 21:35:05 (GMT)
commitb54a99d6432de93de85be2b42a63774f8b4581a0 (patch)
tree59e273ca69f89e6c7eedf91f458ee3cc50eb7cf8 /Include/internal
parentcfc3c2f8b34d3864717ab584c5b6c260014ba55a (diff)
downloadcpython-b54a99d6432de93de85be2b42a63774f8b4581a0.zip
cpython-b54a99d6432de93de85be2b42a63774f8b4581a0.tar.gz
cpython-b54a99d6432de93de85be2b42a63774f8b4581a0.tar.bz2
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.
Diffstat (limited to 'Include/internal')
-rw-r--r--Include/internal/pycore_ceval.h4
-rw-r--r--Include/internal/pycore_pystate.h13
2 files changed, 11 insertions, 6 deletions
diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h
index 1f96fc6..811aada 100644
--- a/Include/internal/pycore_ceval.h
+++ b/Include/internal/pycore_ceval.h
@@ -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);
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index fba0b6f..13a957a 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -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 */