This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: msvcrt.ungetwch() calls _ungetch()
Type: behavior Stage: resolved
Components: Extension Modules, Windows Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, arigo, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2016-07-17 08:43 by arigo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
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);
        Py_INCREF(Py_None);
        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.
msg360161 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-01-17 06:52
Python 2 is EOL, so I think this issue should be closed.
msg360198 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2020-01-17 16:19
If this isn't an issue in Python 3, I agree.
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71727
2020-04-26 01:56:09zach.waresetstatus: open -> closed
resolution: out of date
stage: needs patch -> resolved
2020-01-17 16:19:48zach.waresetmessages: + msg360198
2020-01-17 06:52:35ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg360161
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