summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-12-10 15:12:41 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-12-10 15:12:41 (GMT)
commit7c7f6afa928c24221f8463a1aa71fc6ef532d29e (patch)
tree8def7775fe40f5b218b9c3cae34527cc714e7ec6 /PC
parente6daafb449c57f3fafd11c2513f96bf6f6ca130e (diff)
downloadcpython-7c7f6afa928c24221f8463a1aa71fc6ef532d29e.zip
cpython-7c7f6afa928c24221f8463a1aa71fc6ef532d29e.tar.gz
cpython-7c7f6afa928c24221f8463a1aa71fc6ef532d29e.tar.bz2
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Diffstat (limited to 'PC')
-rwxr-xr-xPC/msvcrtmodule.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c
index 3311bd7..982c458 100755
--- a/PC/msvcrtmodule.c
+++ b/PC/msvcrtmodule.c
@@ -144,6 +144,22 @@ msvcrt_getch(PyObject *self, PyObject *args)
}
static PyObject *
+msvcrt_getwch(PyObject *self, PyObject *args)
+{
+ Py_UNICODE ch;
+ Py_UNICODE u[1];
+
+ if (!PyArg_ParseTuple(args, ":getwch"))
+ return NULL;
+
+ Py_BEGIN_ALLOW_THREADS
+ ch = _getwch();
+ Py_END_ALLOW_THREADS
+ u[0] = ch;
+ return PyUnicode_FromUnicode(u, 1);
+}
+
+static PyObject *
msvcrt_getche(PyObject *self, PyObject *args)
{
int ch;
@@ -160,6 +176,22 @@ msvcrt_getche(PyObject *self, PyObject *args)
}
static PyObject *
+msvcrt_getwche(PyObject *self, PyObject *args)
+{
+ Py_UNICODE ch;
+ Py_UNICODE s[1];
+
+ if (!PyArg_ParseTuple(args, ":getwche"))
+ return NULL;
+
+ Py_BEGIN_ALLOW_THREADS
+ ch = _getwche();
+ Py_END_ALLOW_THREADS
+ s[0] = ch;
+ return PyUnicode_FromUnicode(s, 1);
+}
+
+static PyObject *
msvcrt_putch(PyObject *self, PyObject *args)
{
char ch;
@@ -172,6 +204,25 @@ msvcrt_putch(PyObject *self, PyObject *args)
return Py_None;
}
+
+static PyObject *
+msvcrt_putwch(PyObject *self, PyObject *args)
+{
+ Py_UNICODE *ch;
+ int size;
+
+ if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size))
+ return NULL;
+
+ if (size == 1)
+ _putwch(*ch);
+ Py_RETURN_NONE;
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "Expected unicode of length 1");
+ }
+}
+
static PyObject *
msvcrt_ungetch(PyObject *self, PyObject *args)
{
@@ -186,6 +237,19 @@ msvcrt_ungetch(PyObject *self, PyObject *args)
return Py_None;
}
+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;
+}
static void
insertint(PyObject *d, char *name, int value)
@@ -214,6 +278,11 @@ static struct PyMethodDef msvcrt_functions[] = {
{"getche", msvcrt_getche, METH_VARARGS},
{"putch", msvcrt_putch, METH_VARARGS},
{"ungetch", msvcrt_ungetch, METH_VARARGS},
+ {"getwch", msvcrt_getwch, METH_VARARGS},
+ {"getwche", msvcrt_getwche, METH_VARARGS},
+ {"putwch", msvcrt_putwch, METH_VARARGS},
+ {"ungetwch", msvcrt_ungetwch, METH_VARARGS},
+
{NULL, NULL}
};