summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-03 17:49:25 +0200
committerGitHub <noreply@github.com>2020-06-03 17:49:25 +0200
commit5d2396c8cf68fba0a949c6ce474a505e3aba9c1f (patch)
tree5a0ebd090249175530372137c2ba465f2c020c4e /Modules
parentUpdate error message in _zoneinfo.py to use f-string (GH-20577) (diff)
downloadcpython-5d2396c8cf68fba0a949c6ce474a505e3aba9c1f.tar.gz
cpython-5d2396c8cf68fba0a949c6ce474a505e3aba9c1f.tar.bz2
cpython-5d2396c8cf68fba0a949c6ce474a505e3aba9c1f.zip
[3.9] bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20613)
* bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20579) Fix GIL usage in PyOS_Readline(): lock the GIL to set an exception. Pass tstate to my_fgets() and _PyOS_WindowsConsoleReadline(). Cleanup these functions. (cherry picked from commit c353764fd564e401cf47a5d9efab18c72c60014e) * bpo-40826: Add _PyOS_InterruptOccurred(tstate) function (GH-20599) my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for pending signals, rather calling PyOS_InterruptOccurred(). my_fgets() is called with the GIL released, whereas PyOS_InterruptOccurred() must be called with the GIL held. test_repl: use text=True and avoid SuppressCrashReport in test_multiline_string_parsing(). Fix my_fgets() on Windows: fgets(fp) does crash if fileno(fp) is closed. (cherry picked from commit fa7ab6aa0f9a4f695e5525db5a113cd21fa93787)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/signalmodule.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 8348971c353..b3f5904feb7 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -1779,11 +1779,13 @@ PyOS_FiniInterrupts(void)
finisignal();
}
+
+// The caller doesn't have to hold the GIL
int
-PyOS_InterruptOccurred(void)
+_PyOS_InterruptOccurred(PyThreadState *tstate)
{
- PyInterpreterState *interp = _PyInterpreterState_GET();
- if (!_Py_ThreadCanHandleSignals(interp)) {
+ assert(tstate != NULL);
+ if (!_Py_ThreadCanHandleSignals(tstate->interp)) {
return 0;
}
@@ -1795,6 +1797,16 @@ PyOS_InterruptOccurred(void)
return 1;
}
+
+// The caller must to hold the GIL
+int
+PyOS_InterruptOccurred(void)
+{
+ PyThreadState *tstate = _PyThreadState_GET();
+ return _PyOS_InterruptOccurred(tstate);
+}
+
+
static void
_clear_pending_signals(void)
{