diff -r 3bb3e6316098 Doc/library/msvcrt.rst --- a/Doc/library/msvcrt.rst Sun Apr 17 01:42:33 2016 +1000 +++ b/Doc/library/msvcrt.rst Sun Apr 17 01:38:53 2016 -0700 @@ -6,6 +6,9 @@ :synopsis: Miscellaneous useful routines from the MS VC++ runtime. .. sectionauthor:: Fred L. Drake, Jr. +**Source code:** :source:`PC/msvcrtmodule.c` + +-------------- These functions provide access to some useful capabilities on Windows platforms. Some higher-level modules use these functions to build the Windows @@ -101,32 +104,41 @@ pressed. If the pressed key was a special function key, this will return ``'\000'`` or ``'\xe0'``; the next call will return the keycode. The :kbd:`Control-C` keypress cannot be read with this function. + Raises :exc:`OSError` if console is not connected and nothing has + been "pushed back" with ungetch. .. function:: getwch() - Wide char variant of :func:`getch`, returning a Unicode value. - + Wide char variant of :func:`getch`, returning a Unicode value. Raises + :exc:`OSError` if console is not connected and nothing has been + "pushed back" with ungetwch. + .. function:: getche() - Similar to :func:`getch`, but the keypress will be echoed if it represents a - printable character. + Similar to :func:`getch`, but the keypress will be echoed if it represents a + printable character. Raises :exc:`OSError` if console is not connected and + nothing has been "pushed back" with ungetch. .. function:: getwche() - Wide char variant of :func:`getche`, returning a Unicode value. + Wide char variant of :func:`getche`, returning a Unicode value. Raises + :exc:`OSError` if console is not connected and nothing has been + "pushed back" with ungetwch. .. function:: putch(char) - Print the byte string *char* to the console without buffering. + Print the byte string *char* to the console without buffering. Raises + :exc:`OSError` if console is not connected. .. function:: putwch(unicode_char) - Wide char variant of :func:`putch`, accepting a Unicode value. + Wide char variant of :func:`putch`, accepting a Unicode value. Raises + :exc:`OSError` if console is not connected. .. function:: ungetch(char) diff -r 3bb3e6316098 Misc/NEWS --- a/Misc/NEWS Sun Apr 17 01:42:33 2016 +1000 +++ b/Misc/NEWS Sun Apr 17 01:38:53 2016 -0700 @@ -824,6 +824,9 @@ - Issue #26406: Avoid unnecessary serialization of getaddrinfo(3) calls on current versions of OpenBSD and NetBSD. Patch by A. Jesse Jiryu Davis. +- Issue #25386: In msvcrt, getch, getwch, getche, getwche, putch, and putwch + now raise an OSError when not connected to a terminal. Patch by Josh Snider. + IDLE ---- diff -r 3bb3e6316098 PC/msvcrtmodule.c --- a/PC/msvcrtmodule.c Sun Apr 17 01:42:33 2016 +1000 +++ b/PC/msvcrtmodule.c Sun Apr 17 01:38:53 2016 -0700 @@ -239,6 +239,8 @@ Py_BEGIN_ALLOW_THREADS ch = _getch(); Py_END_ALLOW_THREADS + if (ch == EOF) + PyErr_SetFromErrno(PyExc_IOError); return ch; } @@ -257,6 +259,8 @@ Py_BEGIN_ALLOW_THREADS ch = _getwch(); Py_END_ALLOW_THREADS + if (ch == WEOF) + PyErr_SetFromErrno(PyExc_IOError); return ch; } @@ -275,6 +279,8 @@ Py_BEGIN_ALLOW_THREADS ch = _getche(); Py_END_ALLOW_THREADS + if (ch == EOF) + PyErr_SetFromErrno(PyExc_IOError); return ch; } @@ -293,6 +299,8 @@ Py_BEGIN_ALLOW_THREADS ch = _getwche(); Py_END_ALLOW_THREADS + if (ch == WEOF) + PyErr_SetFromErrno(PyExc_IOError); return ch; } @@ -309,7 +317,8 @@ msvcrt_putch_impl(PyModuleDef *module, char char_value) /*[clinic end generated code: output=c05548b11554f36f input=ec078dd10cb054d6]*/ { - _putch(char_value); + if (_putch(char_value) == EOF) + return PyErr_SetFromErrno(PyExc_IOError); Py_RETURN_NONE; } @@ -326,7 +335,8 @@ msvcrt_putwch_impl(PyModuleDef *module, int unicode_char) /*[clinic end generated code: output=c216a73694ca73dd input=996ccd0bbcbac4c3]*/ { - _putwch(unicode_char); + if (_putwch(unicode_char) == WEOF) + return PyErr_SetFromErrno(PyExc_IOError); Py_RETURN_NONE; }