Index: PC/msvcrtmodule.c =================================================================== --- PC/msvcrtmodule.c (revision 70127) +++ PC/msvcrtmodule.c (working copy) @@ -206,12 +206,18 @@ static PyObject * msvcrt_putch(PyObject *self, PyObject *args) { - char ch; + char *ch; + int size; - if (!PyArg_ParseTuple(args, "c:putch", &ch)) + if (!PyArg_ParseTuple(args, "y#:putch", &ch, &size)) return NULL; - _putch(ch); + if (size != 1) { + PyErr_SetString(PyExc_ValueError, + "Expected bytes of length 1"); + return NULL; + } + _putch(*ch); Py_INCREF(Py_None); return Py_None; } @@ -226,7 +232,7 @@ if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size)) return NULL; - if (size == 0) { + if (size != 1) { PyErr_SetString(PyExc_ValueError, "Expected unicode string of length 1"); return NULL; @@ -240,12 +246,18 @@ static PyObject * msvcrt_ungetch(PyObject *self, PyObject *args) { - char ch; + char *ch; + int size; - if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) + if (!PyArg_ParseTuple(args, "y#:ungetch", &ch, &size)) return NULL; - if (_ungetch(ch) == EOF) + if (size != 1) { + PyErr_SetString(PyExc_ValueError, + "Expected bytes of length 1"); + return NULL; + } + if (_ungetch(*ch) == EOF) return PyErr_SetFromErrno(PyExc_IOError); Py_INCREF(Py_None); return Py_None; @@ -255,12 +267,18 @@ static PyObject * msvcrt_ungetwch(PyObject *self, PyObject *args) { - Py_UNICODE ch; + Py_UNICODE *ch; + int size; - if (!PyArg_ParseTuple(args, "u:ungetwch", &ch)) + if (!PyArg_ParseTuple(args, "u#:ungetwch", &ch, &size)) return NULL; - if (_ungetch(ch) == EOF) + if (size != 1) { + PyErr_SetString(PyExc_ValueError, + "Expected unicode string of length 1"); + return NULL; + } + if (_ungetwch(*ch) == EOF) return PyErr_SetFromErrno(PyExc_IOError); Py_INCREF(Py_None); return Py_None;