[Python-checkins] bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. (GH-7911)

Steve Dower webhook-mailer at python.org
Sun Jul 29 05:32:05 EDT 2018


https://github.com/python/cpython/commit/c3af73d580888b4d444264e79dce6ec0818522cd
commit: c3af73d580888b4d444264e79dce6ec0818522cd
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Steve Dower <steve.dower at microsoft.com>
date: 2018-07-29T10:32:02+01:00
summary:

bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. (GH-7911)

(cherry picked from commit ce75df3031c86b78311b1ad76c39c0b39d7d7424)

Co-authored-by: ValeriyaSinevich <valeriya.sinevich at phystech.edu>

files:
A Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst
M Modules/_io/winconsoleio.c
M Parser/myreadline.c

diff --git a/Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst b/Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst
new file mode 100644
index 000000000000..18aac756cb58
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2018-06-25-09-33-48.bpo-30237.EybiZA.rst
@@ -0,0 +1,2 @@
+Output error when ReadConsole is canceled by CancelSynchronousIo instead of
+crashing.
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index b85c11b3405a..4d3d695e4210 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -556,7 +556,8 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
     Py_BEGIN_ALLOW_THREADS
     DWORD off = 0;
     while (off < maxlen) {
-        DWORD n, len = min(maxlen - off, BUFSIZ);
+        DWORD n = (DWORD)-1; 
+        DWORD len = min(maxlen - off, BUFSIZ);
         SetLastError(0);
         BOOL res = ReadConsoleW(handle, &buf[off], len, &n, NULL);
 
@@ -564,6 +565,9 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
             err = GetLastError();
             break;
         }
+        if (n == (DWORD)-1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
+            break;
+        }
         if (n == 0) {
             err = GetLastError();
             if (err != ERROR_OPERATION_ABORTED)
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index 2aa3bef2b0bb..edb291a6691a 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -109,7 +109,7 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn)
     char *buf = NULL;
     int err = 0;
 
-    n_read = 0;
+    n_read = (DWORD)-1;
     total_read = 0;
     wbuf = wbuf_local;
     wbuflen = sizeof(wbuf_local) / sizeof(wbuf_local[0]) - 1;
@@ -121,6 +121,9 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn)
             err = GetLastError();
             goto exit;
         }
+        if (n_read == (DWORD)-1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
+            break;
+        }
         if (n_read == 0) {
             int s;
             err = GetLastError();



More information about the Python-checkins mailing list