diff options
author | Victor Stinner <vstinner@python.org> | 2020-06-03 20:16:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-03 20:16:39 +0200 |
commit | 6d62dc1ea4e191b8486e80a85ca0694215375424 (patch) | |
tree | c8e424712610a6f281e4b566e5e854103eea9ecb /Include/internal | |
parent | 5d2396c8cf68fba0a949c6ce474a505e3aba9c1f (diff) | |
download | cpython-git-6d62dc1ea4e191b8486e80a85ca0694215375424.tar.gz |
[3.9] bpo-40826: PyOS_InterruptOccurred() requires GIL (GH-20578) (GH-20618)
* bpo-40826: Add _Py_EnsureTstateNotNULL() macro (GH-20571)
Add _Py_EnsureTstateNotNULL(tstate) macro: call Py_FatalError() if
tstate is NULL, the error message contains the current function name.
(cherry picked from commit 3026cad59b87751a9215111776cac8e819458fce)
* bpo-40826: PyOS_InterruptOccurred() requires GIL (GH-20578)
PyOS_InterruptOccurred() now fails with a fatal error if it is called
with the GIL released.
(cherry picked from commit cbe129692293251e7fbcea9ff0d822824d90c140)
Diffstat (limited to 'Include/internal')
-rw-r--r-- | Include/internal/pycore_pystate.h | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index a9515b40c3..835d6e029c 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -74,6 +74,21 @@ _PyThreadState_GET(void) #undef PyThreadState_GET #define PyThreadState_GET() _PyThreadState_GET() +PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalError_TstateNULL(const char *func); + +static inline void +_Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate) +{ + if (tstate == NULL) { + _Py_FatalError_TstateNULL(func); + } +} + +// Call Py_FatalError() if tstate is NULL +#define _Py_EnsureTstateNotNULL(tstate) \ + _Py_EnsureFuncTstateNotNULL(__func__, tstate) + + /* Get the current interpreter state. The macro is unsafe: it does not check for error and it can return NULL. @@ -84,7 +99,9 @@ _PyThreadState_GET(void) and _PyGILState_GetInterpreterStateUnsafe(). */ static inline PyInterpreterState* _PyInterpreterState_GET(void) { PyThreadState *tstate = _PyThreadState_GET(); - assert(tstate != NULL); +#ifdef Py_DEBUG + _Py_EnsureTstateNotNULL(tstate); +#endif return tstate->interp; } |