From 81026c9772c1c3ebacd901afaaf91922506c5fe9 Mon Sep 17 00:00:00 2001 From: "E. Paine" <63801254+E-Paine@users.noreply.github.com> Date: Tue, 29 Sep 2020 18:09:54 +0100 Subject: [PATCH 1/3] Acquire GIL before getting thread state --- Modules/_tkinter.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 793c5e71548846..6bb7ac3bf7a0c5 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -261,6 +261,10 @@ static PyThreadState *tcl_tstate = NULL; #define ENTER_PYTHON \ { PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \ + if(tstate == NULL) { \ + PyGILState_STATE gstate = PyGILState_Ensure(); \ + tstate = PyThreadState_Get(); \ + PyGILState_Release(gstate); } \ if(tcl_lock) \ PyThread_release_lock(tcl_lock); PyEval_RestoreThread((tstate)); } From abbd15407e1adb271f8a94043d6c33c75ed2ec6d Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2020 17:13:59 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst diff --git a/Misc/NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst b/Misc/NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst new file mode 100644 index 00000000000000..9f9ccc3c8b6d60 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst @@ -0,0 +1 @@ +_tkinter correctly handles a null thread state when trying to restore the state. \ No newline at end of file From 07279828cb2c474fe3020afb292c1fd2722b1ccf Mon Sep 17 00:00:00 2001 From: E-Paine <63801254+E-Paine@users.noreply.github.com> Date: Tue, 29 Sep 2020 18:17:11 +0100 Subject: [PATCH 3/3] Use Thomas' news entry from the previous PR --- .../next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst b/Misc/NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst index 9f9ccc3c8b6d60..20255395518f12 100644 --- a/Misc/NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst +++ b/Misc/NEWS.d/next/Library/2020-09-29-17-13-58.bpo-40075.pQAxXp.rst @@ -1 +1 @@ -_tkinter correctly handles a null thread state when trying to restore the state. \ No newline at end of file +Fix a crash in ``_tkinter`` on Windows where ``ENTER_PYTHON`` may try to restore a NULL state.