Title: msvcrt.ungetwch() calls _ungetch()
Type: behavior Stage: needs patch
Components: Extension Modules, Windows Versions: Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: arigo, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2016-07-17 08:43 by arigo, last changed 2016-07-17 19:39 by arigo.

Messages (3)
msg270620 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2016-07-17 08:43
In Python 2.7, PC/msvcrtmodule.c, the function msvcrt_ungetwch() calls _ungetch() instead of _ungetwch() as was probably intended.
msg270648 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-07-17 15:50
Parsing the argument is also broken:

    static PyObject *
    msvcrt_ungetwch(PyObject *self, PyObject *args)
        Py_UNICODE ch;

        if (!PyArg_ParseTuple(args, "u:ungetwch", &ch))
            return NULL;

        if (_ungetch(ch) == EOF)
            return PyErr_SetFromErrno(PyExc_IOError);
        return Py_None;

Format "u" is a `Py_UNICODE *`. There's no "C" format code in 2.x, so it will first have to check that the string length is exactly 1 and then use index 0.
msg270665 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2016-07-17 19:39
Uh, you're right.  Then I can also add that putwch() strangely checks for unicode strings of length != 0 instead of == 1, despite what it says it its error message.  These functions appear not to be tested or even (in case of ungetwch()) used by anyone.
Date User Action Args
2016-07-17 19:39:25arigosetmessages: + msg270665
2016-07-17 15:50:26eryksunsetnosy: + paul.moore, tim.golden, eryksun, zach.ware, steve.dower
messages: + msg270648

components: + Windows
stage: needs patch
2016-07-17 08:43:32arigocreate