mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[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 commit3026cad59b
) * 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 commitcbe1296922
)
This commit is contained in:
parent
5d2396c8cf
commit
6d62dc1ea4
8 changed files with 43 additions and 31 deletions
|
@ -39,16 +39,6 @@ extern "C" {
|
|||
_Py_atomic_store_relaxed(&(gilstate)->tstate_current, \
|
||||
(uintptr_t)(value))
|
||||
|
||||
static void
|
||||
ensure_tstate_not_null(const char *func, PyThreadState *tstate)
|
||||
{
|
||||
if (tstate == NULL) {
|
||||
_Py_FatalErrorFunc(func,
|
||||
"current thread state is NULL (released GIL?)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
static PyThreadState *_PyGILState_GetThisThreadState(struct _gilstate_runtime_state *gilstate);
|
||||
static void _PyThreadState_Delete(PyThreadState *tstate, int check_current);
|
||||
|
@ -431,7 +421,7 @@ PyInterpreterState *
|
|||
PyInterpreterState_Get(void)
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
if (interp == NULL) {
|
||||
Py_FatalError("no current interpreter");
|
||||
|
@ -846,7 +836,7 @@ static void
|
|||
tstate_delete_common(PyThreadState *tstate,
|
||||
struct _gilstate_runtime_state *gilstate)
|
||||
{
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
if (interp == NULL) {
|
||||
Py_FatalError("NULL interpreter");
|
||||
|
@ -897,7 +887,7 @@ PyThreadState_Delete(PyThreadState *tstate)
|
|||
void
|
||||
_PyThreadState_DeleteCurrent(PyThreadState *tstate)
|
||||
{
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
|
||||
tstate_delete_common(tstate, gilstate);
|
||||
_PyRuntimeGILState_SetThreadState(gilstate, NULL);
|
||||
|
@ -967,7 +957,7 @@ PyThreadState *
|
|||
PyThreadState_Get(void)
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
return tstate;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue