diff -r 52fbc7bb78ad PC/msvcrtmodule.c --- a/PC/msvcrtmodule.c Sat Jan 11 00:16:50 2014 +0100 +++ b/PC/msvcrtmodule.c Sat Jan 11 01:08:38 2014 -0600 @@ -32,39 +32,112 @@ #endif #endif -// Force the malloc heap to clean itself up, and free unused blocks -// back to the OS. (According to the docs, only works on NT.) +/*[clinic input] +module msvcrt +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + +/*[clinic input] +msvcrt.heapmin + +Minimize the malloc() heap. + +Force the malloc() heap to clean itself up and return unused blocks +to the operating system. On failure, this raises OSError. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_heapmin__doc__, +"heapmin()\n" +"Minimize the malloc() heap.\n" +"\n" +"Force the malloc() heap to clean itself up and return unused blocks\n" +"to the operating system. On failure, this raises OSError."); + +#define MSVCRT_HEAPMIN_METHODDEF \ + {"heapmin", (PyCFunction)msvcrt_heapmin, METH_NOARGS, msvcrt_heapmin__doc__}, + static PyObject * -msvcrt_heapmin(PyObject *self, PyObject *args) +msvcrt_heapmin_impl(PyModuleDef *module); + +static PyObject * +msvcrt_heapmin(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) { - if (!PyArg_ParseTuple(args, ":heapmin")) - return NULL; + PyObject *return_value = NULL; + return_value = msvcrt_heapmin_impl(module); + + return return_value; +} + +static PyObject * +msvcrt_heapmin_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=d0c9471b525728727f51b70ba2d7fdb07619902d]*/ +{ if (_heapmin() != 0) return PyErr_SetFromErrno(PyExc_IOError); Py_INCREF(Py_None); return Py_None; } +/*[clinic input] +msvcrt.locking -PyDoc_STRVAR(heapmin_doc, -"heapmin() -> None\n\ -\n\ -Force the malloc() heap to clean itself up and return unused blocks\n\ -to the operating system. On failure, this raises IOError."); + fd: int + mode: int + nbytes: long + / -// Perform locking operations on a C runtime file descriptor. +Lock part of a file based on file descriptor fd from the C runtime. + +Raises IOError on failure. The locked region of the file extends from +the current file position for nbytes bytes, and may continue beyond +the end of the file. mode must be one of the LK_* constants listed +below. Multiple regions in a file may be locked at the same time, but +may not overlap. Adjacent regions are not merged; they must be unlocked +individually. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_locking__doc__, +"locking(fd, mode, nbytes)\n" +"Lock part of a file based on file descriptor fd from the C runtime.\n" +"\n" +"Raises IOError on failure. The locked region of the file extends from\n" +"the current file position for nbytes bytes, and may continue beyond\n" +"the end of the file. mode must be one of the LK_* constants listed\n" +"below. Multiple regions in a file may be locked at the same time, but\n" +"may not overlap. Adjacent regions are not merged; they must be unlocked\n" +"individually."); + +#define MSVCRT_LOCKING_METHODDEF \ + {"locking", (PyCFunction)msvcrt_locking, METH_VARARGS, msvcrt_locking__doc__}, + static PyObject * -msvcrt_locking(PyObject *self, PyObject *args) +msvcrt_locking_impl(PyModuleDef *module, int fd, int mode, long nbytes); + +static PyObject * +msvcrt_locking(PyModuleDef *module, PyObject *args) { + PyObject *return_value = NULL; int fd; int mode; long nbytes; + + if (!PyArg_ParseTuple(args, + "iil:locking", + &fd, &mode, &nbytes)) + goto exit; + return_value = msvcrt_locking_impl(module, fd, mode, nbytes); + +exit: + return return_value; +} + +static PyObject * +msvcrt_locking_impl(PyModuleDef *module, int fd, int mode, long nbytes) +/*[clinic end generated code: checksum=c6f0c14e56c9c3b2df85469036d47166d39a2665]*/ +{ int err; - if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes)) - return NULL; - Py_BEGIN_ALLOW_THREADS err = _locking(fd, mode, nbytes); Py_END_ALLOW_THREADS @@ -75,51 +148,120 @@ return Py_None; } -PyDoc_STRVAR(locking_doc, -"locking(fd, mode, nbytes) -> None\n\ -\n\ -Lock part of a file based on file descriptor fd from the C runtime.\n\ -Raises IOError on failure. The locked region of the file extends from\n\ -the current file position for nbytes bytes, and may continue beyond\n\ -the end of the file. mode must be one of the LK_* constants listed\n\ -below. Multiple regions in a file may be locked at the same time, but\n\ -may not overlap. Adjacent regions are not merged; they must be unlocked\n\ -individually."); +/*[clinic input] +msvcrt.setmode -// Set the file translation mode for a C runtime file descriptor. + fd: int + mode: int + / + +Set the line-end translation mode for the file descriptor fd. + +To set it to text mode, flags should be os.O_TEXT; for binary, it should be +os.O_BINARY. + +Return value is the previous mode. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_setmode__doc__, +"setmode(fd, mode)\n" +"Set the line-end translation mode for the file descriptor fd.\n" +"\n" +"To set it to text mode, flags should be os.O_TEXT; for binary, it should be\n" +"os.O_BINARY.\n" +"\n" +"Return value is the previous mode."); + +#define MSVCRT_SETMODE_METHODDEF \ + {"setmode", (PyCFunction)msvcrt_setmode, METH_VARARGS, msvcrt_setmode__doc__}, + static PyObject * -msvcrt_setmode(PyObject *self, PyObject *args) +msvcrt_setmode_impl(PyModuleDef *module, int fd, int mode); + +static PyObject * +msvcrt_setmode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int fd; + int mode; + + if (!PyArg_ParseTuple(args, + "ii:setmode", + &fd, &mode)) + goto exit; + return_value = msvcrt_setmode_impl(module, fd, mode); + +exit: + return return_value; +} + +static PyObject * +msvcrt_setmode_impl(PyModuleDef *module, int fd, int mode) +/*[clinic end generated code: checksum=49774858a9745f4086eb4d96868e7ff351e26469]*/ +{ + mode = _setmode(fd, mode); + if (mode == -1) + return PyErr_SetFromErrno(PyExc_IOError); + + return PyLong_FromLong(mode); +} + +/*[python input] +class Py_intptr_t_converter(CConverter): + type = 'Py_intptr_t' + format_unit = '"_Py_PARSE_INTPTR"' +[python start generated code]*/ +/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ +/*[clinic input] +msvcrt.open_osfhandle + + handle: Py_intptr_t + flags: int + / + +Create a C runtime file descriptor from the file handle handle. + +The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY, +and os.O_TEXT. The returned file descriptor may be used as a parameter +to os.fdopen() to create a file object. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_open_osfhandle__doc__, +"open_osfhandle(handle, flags)\n" +"Create a C runtime file descriptor from the file handle handle.\n" +"\n" +"The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n" +"and os.O_TEXT. The returned file descriptor may be used as a parameter\n" +"to os.fdopen() to create a file object."); + +#define MSVCRT_OPEN_OSFHANDLE_METHODDEF \ + {"open_osfhandle", (PyCFunction)msvcrt_open_osfhandle, METH_VARARGS, msvcrt_open_osfhandle__doc__}, + +static PyObject * +msvcrt_open_osfhandle_impl(PyModuleDef *module, Py_intptr_t handle, int flags); + +static PyObject * +msvcrt_open_osfhandle(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_intptr_t handle; + int flags; + + if (!PyArg_ParseTuple(args, + ""_Py_PARSE_INTPTR"i:open_osfhandle", + &handle, &flags)) + goto exit; + return_value = msvcrt_open_osfhandle_impl(module, handle, flags); + +exit: + return return_value; +} + +static PyObject * +msvcrt_open_osfhandle_impl(PyModuleDef *module, Py_intptr_t handle, int flags) +/*[clinic end generated code: checksum=eeabcacacd620669c7a970aa214e1a36b92f0e57]*/ { int fd; - int flags; - if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags)) - return NULL; - - flags = _setmode(fd, flags); - if (flags == -1) - return PyErr_SetFromErrno(PyExc_IOError); - - return PyLong_FromLong(flags); -} - -PyDoc_STRVAR(setmode_doc, -"setmode(fd, mode) -> Previous mode\n\ -\n\ -Set the line-end translation mode for the file descriptor fd. To set\n\ -it to text mode, flags should be os.O_TEXT; for binary, it should be\n\ -os.O_BINARY."); - -// Convert an OS file handle to a C runtime file descriptor. -static PyObject * -msvcrt_open_osfhandle(PyObject *self, PyObject *args) -{ - Py_intptr_t handle; - int flags; - int fd; - - if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR "i:open_osfhandle", - &handle, &flags)) - return NULL; fd = _open_osfhandle(handle, flags); if (fd == -1) @@ -128,24 +270,51 @@ return PyLong_FromLong(fd); } -PyDoc_STRVAR(open_osfhandle_doc, -"open_osfhandle(handle, flags) -> file descriptor\n\ -\n\ -Create a C runtime file descriptor from the file handle handle. The\n\ -flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n\ -and os.O_TEXT. The returned file descriptor may be used as a parameter\n\ -to os.fdopen() to create a file object."); +/*[clinic input] +msvcrt.get_osfhandle -// Convert a C runtime file descriptor to an OS file handle. + fd: int + / + +Return the file handle for the file descriptor fd. + +Raises IOError if fd is not recognized. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_get_osfhandle__doc__, +"get_osfhandle(fd)\n" +"Return the file handle for the file descriptor fd.\n" +"\n" +"Raises IOError if fd is not recognized."); + +#define MSVCRT_GET_OSFHANDLE_METHODDEF \ + {"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_VARARGS, msvcrt_get_osfhandle__doc__}, + static PyObject * -msvcrt_get_osfhandle(PyObject *self, PyObject *args) +msvcrt_get_osfhandle_impl(PyModuleDef *module, int fd); + +static PyObject * +msvcrt_get_osfhandle(PyModuleDef *module, PyObject *args) { + PyObject *return_value = NULL; int fd; + + if (!PyArg_ParseTuple(args, + "i:get_osfhandle", + &fd)) + goto exit; + return_value = msvcrt_get_osfhandle_impl(module, fd); + +exit: + return return_value; +} + +static PyObject * +msvcrt_get_osfhandle_impl(PyModuleDef *module, int fd) +/*[clinic end generated code: checksum=5b4ba8af665f31cc6d8228241d6453f4a3c415e6]*/ +{ Py_intptr_t handle; - if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) - return NULL; - if (!_PyVerify_fd(fd)) return PyErr_SetFromErrno(PyExc_IOError); @@ -159,40 +328,88 @@ return PyLong_FromVoidPtr((void*)handle); } -PyDoc_STRVAR(get_osfhandle_doc, -"get_osfhandle(fd) -> file handle\n\ -\n\ -Return the file handle for the file descriptor fd. Raises IOError\n\ -if fd is not recognized."); +/* Console I/O */ +/*[clinic input] +msvcrt.kbhit -/* Console I/O */ +Return true if a keypress is waiting to be read. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_kbhit__doc__, +"kbhit()\n" +"Return true if a keypress is waiting to be read."); + +#define MSVCRT_KBHIT_METHODDEF \ + {"kbhit", (PyCFunction)msvcrt_kbhit, METH_NOARGS, msvcrt_kbhit__doc__}, static PyObject * -msvcrt_kbhit(PyObject *self, PyObject *args) +msvcrt_kbhit_impl(PyModuleDef *module); + +static PyObject * +msvcrt_kbhit(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = msvcrt_kbhit_impl(module); + + return return_value; +} + +static PyObject * +msvcrt_kbhit_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=6f10f7881ff985925c97c7e163fddce28ae749f2]*/ { int ok; - if (!PyArg_ParseTuple(args, ":kbhit")) - return NULL; - ok = _kbhit(); return PyLong_FromLong(ok); } -PyDoc_STRVAR(kbhit_doc, -"kbhit() -> bool\n\ -\n\ -Return true if a keypress is waiting to be read."); +/*[clinic input] +msvcrt.getch + +Read a keypress and return the resulting character as a byte string. + +Nothing is echoed to the console. This call will block if a keypress is +not already available, but will not wait for Enter to be pressed. If the +pressed key was a special function key, this will return '\\000' or +'\\xe0'; the next call will return the keycode. The Control-C keypress +cannot be read with this function. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_getch__doc__, +"getch()\n" +"Read a keypress and return the resulting character as a byte string.\n" +"\n" +"Nothing is echoed to the console. This call will block if a keypress is\n" +"not already available, but will not wait for Enter to be pressed. If the\n" +"pressed key was a special function key, this will return \'\\000\' or\n" +"\'\\xe0\'; the next call will return the keycode. The Control-C keypress\n" +"cannot be read with this function."); + +#define MSVCRT_GETCH_METHODDEF \ + {"getch", (PyCFunction)msvcrt_getch, METH_NOARGS, msvcrt_getch__doc__}, static PyObject * -msvcrt_getch(PyObject *self, PyObject *args) +msvcrt_getch_impl(PyModuleDef *module); + +static PyObject * +msvcrt_getch(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = msvcrt_getch_impl(module); + + return return_value; +} + +static PyObject * +msvcrt_getch_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=e8836714d97ec61ae8a1bf6dc0b643c492b837f9]*/ { int ch; char s[1]; - if (!PyArg_ParseTuple(args, ":getch")) - return NULL; - Py_BEGIN_ALLOW_THREADS ch = _getch(); Py_END_ALLOW_THREADS @@ -200,46 +417,79 @@ return PyBytes_FromStringAndSize(s, 1); } -PyDoc_STRVAR(getch_doc, -"getch() -> key character\n\ -\n\ -Read a keypress and return the resulting character as a byte string.\n\ -Nothing is echoed to the console. This call will block if a keypress is\n\ -not already available, but will not wait for Enter to be pressed. If the\n\ -pressed key was a special function key, this will return '\\000' or\n\ -'\\xe0'; the next call will return the keycode. The Control-C keypress\n\ -cannot be read with this function."); +#ifdef _WCONIO_DEFINED +/*[clinic input] +msvcrt.getwch -#ifdef _WCONIO_DEFINED +Wide char variant of getch(), returning a Unicode value. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_getwch__doc__, +"getwch()\n" +"Wide char variant of getch(), returning a Unicode value."); + +#define MSVCRT_GETWCH_METHODDEF \ + {"getwch", (PyCFunction)msvcrt_getwch, METH_NOARGS, msvcrt_getwch__doc__}, + static PyObject * -msvcrt_getwch(PyObject *self, PyObject *args) +msvcrt_getwch_impl(PyModuleDef *module); + +static PyObject * +msvcrt_getwch(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = msvcrt_getwch_impl(module); + + return return_value; +} + +static PyObject * +msvcrt_getwch_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=a902e8ecc086f94961d630d04766bb0309789b47]*/ { wchar_t ch; - if (!PyArg_ParseTuple(args, ":getwch")) - return NULL; - Py_BEGIN_ALLOW_THREADS ch = _getwch(); Py_END_ALLOW_THREADS return PyUnicode_FromOrdinal(ch); } - -PyDoc_STRVAR(getwch_doc, -"getwch() -> Unicode key character\n\ -\n\ -Wide char variant of getch(), returning a Unicode value."); #endif +/*[clinic input] +msvcrt.getche + +Similar to getch(), but the keypress will be echoed if possible. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_getche__doc__, +"getche()\n" +"Similar to getch(), but the keypress will be echoed if possible."); + +#define MSVCRT_GETCHE_METHODDEF \ + {"getche", (PyCFunction)msvcrt_getche, METH_NOARGS, msvcrt_getche__doc__}, + static PyObject * -msvcrt_getche(PyObject *self, PyObject *args) +msvcrt_getche_impl(PyModuleDef *module); + +static PyObject * +msvcrt_getche(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = msvcrt_getche_impl(module); + + return return_value; +} + +static PyObject * +msvcrt_getche_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=e662379428dc504b687461a5d510e66c5ac95ad6]*/ { int ch; char s[1]; - if (!PyArg_ParseTuple(args, ":getche")) - return NULL; - Py_BEGIN_ALLOW_THREADS ch = _getche(); Py_END_ALLOW_THREADS @@ -247,111 +497,234 @@ return PyBytes_FromStringAndSize(s, 1); } -PyDoc_STRVAR(getche_doc, -"getche() -> key character\n\ -\n\ -Similar to getch(), but the keypress will be echoed if it represents\n\ -a printable character."); +#ifdef _WCONIO_DEFINED +/*[clinic input] +msvcrt.getwche -#ifdef _WCONIO_DEFINED +Wide char variant of getche(), returning a Unicode value. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_getwche__doc__, +"getwche()\n" +"Wide char variant of getche(), returning a Unicode value."); + +#define MSVCRT_GETWCHE_METHODDEF \ + {"getwche", (PyCFunction)msvcrt_getwche, METH_NOARGS, msvcrt_getwche__doc__}, + static PyObject * -msvcrt_getwche(PyObject *self, PyObject *args) +msvcrt_getwche_impl(PyModuleDef *module); + +static PyObject * +msvcrt_getwche(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = msvcrt_getwche_impl(module); + + return return_value; +} + +static PyObject * +msvcrt_getwche_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=8d480cf402d263dc649474af69356a9833a49724]*/ { wchar_t ch; - if (!PyArg_ParseTuple(args, ":getwche")) - return NULL; - Py_BEGIN_ALLOW_THREADS ch = _getwche(); Py_END_ALLOW_THREADS return PyUnicode_FromOrdinal(ch); } - -PyDoc_STRVAR(getwche_doc, -"getwche() -> Unicode key character\n\ -\n\ -Wide char variant of getche(), returning a Unicode value."); #endif +/*[clinic input] +msvcrt.putch + + char: char + / + +Print the byte string char to the console without buffering. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_putch__doc__, +"putch(char)\n" +"Print the byte string char to the console without buffering."); + +#define MSVCRT_PUTCH_METHODDEF \ + {"putch", (PyCFunction)msvcrt_putch, METH_VARARGS, msvcrt_putch__doc__}, + static PyObject * -msvcrt_putch(PyObject *self, PyObject *args) +msvcrt_putch_impl(PyModuleDef *module, char char_value); + +static PyObject * +msvcrt_putch(PyModuleDef *module, PyObject *args) { - char ch; + PyObject *return_value = NULL; + char char_value; - if (!PyArg_ParseTuple(args, "c:putch", &ch)) - return NULL; + if (!PyArg_ParseTuple(args, + "c:putch", + &char_value)) + goto exit; + return_value = msvcrt_putch_impl(module, char_value); - _putch(ch); +exit: + return return_value; +} + +static PyObject * +msvcrt_putch_impl(PyModuleDef *module, char char_value) +/*[clinic end generated code: checksum=2fc9e33223995667ed26c251873404f3040f01e9]*/ +{ + _putch(char_value); Py_INCREF(Py_None); return Py_None; } -PyDoc_STRVAR(putch_doc, -"putch(char) -> None\n\ -\n\ -Print the byte string char to the console without buffering."); +#ifdef _WCONIO_DEFINED +/*[clinic input] +msvcrt.putwch -#ifdef _WCONIO_DEFINED + unicode_char: int(types='str') + / + +Wide char variant of putch(), accepting a Unicode value. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_putwch__doc__, +"putwch(unicode_char)\n" +"Wide char variant of putch(), accepting a Unicode value."); + +#define MSVCRT_PUTWCH_METHODDEF \ + {"putwch", (PyCFunction)msvcrt_putwch, METH_VARARGS, msvcrt_putwch__doc__}, + static PyObject * -msvcrt_putwch(PyObject *self, PyObject *args) +msvcrt_putwch_impl(PyModuleDef *module, int unicode_char); + +static PyObject * +msvcrt_putwch(PyModuleDef *module, PyObject *args) { - int ch; + PyObject *return_value = NULL; + int unicode_char; - if (!PyArg_ParseTuple(args, "C:putwch", &ch)) - return NULL; + if (!PyArg_ParseTuple(args, + "C:putwch", + &unicode_char)) + goto exit; + return_value = msvcrt_putwch_impl(module, unicode_char); - _putwch(ch); +exit: + return return_value; +} + +static PyObject * +msvcrt_putwch_impl(PyModuleDef *module, int unicode_char) +/*[clinic end generated code: checksum=af393175374afa21985c88255ce8fb85264f17fc]*/ +{ + _putwch(unicode_char); Py_RETURN_NONE; } - -PyDoc_STRVAR(putwch_doc, -"putwch(unicode_char) -> None\n\ -\n\ -Wide char variant of putch(), accepting a Unicode value."); #endif +/*[clinic input] +msvcrt.ungetch + + char: char + / + +Opposite of getch. + +Cause the byte string char to be "pushed back" into the +console buffer; it will be the next character read by +getch() or getche(). +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_ungetch__doc__, +"ungetch(char)\n" +"Opposite of getch.\n" +"\n" +"Cause the byte string char to be \"pushed back\" into the\n" +"console buffer; it will be the next character read by\n" +"getch() or getche()."); + +#define MSVCRT_UNGETCH_METHODDEF \ + {"ungetch", (PyCFunction)msvcrt_ungetch, METH_VARARGS, msvcrt_ungetch__doc__}, + static PyObject * -msvcrt_ungetch(PyObject *self, PyObject *args) +msvcrt_ungetch_impl(PyModuleDef *module, char char_value); + +static PyObject * +msvcrt_ungetch(PyModuleDef *module, PyObject *args) { - char ch; + PyObject *return_value = NULL; + char char_value; - if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) - return NULL; + if (!PyArg_ParseTuple(args, + "c:ungetch", + &char_value)) + goto exit; + return_value = msvcrt_ungetch_impl(module, char_value); - if (_ungetch(ch) == EOF) +exit: + return return_value; +} + +static PyObject * +msvcrt_ungetch_impl(PyModuleDef *module, char char_value) +/*[clinic end generated code: checksum=3d8dfc308af5b1fba22d517edc046d5bec1a9bb5]*/ +{ + if (_ungetch(char_value) == EOF) return PyErr_SetFromErrno(PyExc_IOError); Py_INCREF(Py_None); return Py_None; } -PyDoc_STRVAR(ungetch_doc, -"ungetch(char) -> None\n\ -\n\ -Cause the byte string char to be \"pushed back\" into the\n\ -console buffer; it will be the next character read by\n\ -getch() or getche()."); +#ifdef _WCONIO_DEFINED +/*[clinic input] +msvcrt.ungetwch -#ifdef _WCONIO_DEFINED + unicode_char: int(types='str') + / + +Wide char variant of ungetch(), accepting a Unicode value. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_ungetwch__doc__, +"ungetwch(unicode_char)\n" +"Wide char variant of ungetch(), accepting a Unicode value."); + +#define MSVCRT_UNGETWCH_METHODDEF \ + {"ungetwch", (PyCFunction)msvcrt_ungetwch, METH_VARARGS, msvcrt_ungetwch__doc__}, + static PyObject * -msvcrt_ungetwch(PyObject *self, PyObject *args) +msvcrt_ungetwch_impl(PyModuleDef *module, int unicode_char); + +static PyObject * +msvcrt_ungetwch(PyModuleDef *module, PyObject *args) { - int ch; + PyObject *return_value = NULL; + int unicode_char; - if (!PyArg_ParseTuple(args, "C:ungetwch", &ch)) - return NULL; + if (!PyArg_ParseTuple(args, + "C:ungetwch", + &unicode_char)) + goto exit; + return_value = msvcrt_ungetwch_impl(module, unicode_char); - if (_ungetwch(ch) == WEOF) +exit: + return return_value; +} + +static PyObject * +msvcrt_ungetwch_impl(PyModuleDef *module, int unicode_char) +/*[clinic end generated code: checksum=1a2fb68c965930ff1bb524ecce42b8eb055381b2]*/ +{ + if (_ungetwch(unicode_char) == WEOF) return PyErr_SetFromErrno(PyExc_IOError); Py_INCREF(Py_None); return Py_None; } - -PyDoc_STRVAR(ungetwch_doc, -"ungetwch(unicode_char) -> None\n\ -\n\ -Wide char variant of ungetch(), accepting a Unicode value."); #endif static void @@ -370,54 +743,204 @@ #ifdef _DEBUG -static PyObject* -msvcrt_setreportfile(PyObject *self, PyObject *args) +/*[clinic input] +msvcrt.CrtSetReportFile + + type: int + file: int + / + +Wrapper around _CrtSetReportFile. + +Only available on Debug builds. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__, +"CrtSetReportFile(type, file)\n" +"Wrapper around _CrtSetReportFile.\n" +"\n" +"Only available on Debug builds."); + +#define MSVCRT_CRTSETREPORTFILE_METHODDEF \ + {"CrtSetReportFile", (PyCFunction)msvcrt_CrtSetReportFile, METH_VARARGS, msvcrt_CrtSetReportFile__doc__}, + +static PyObject * +msvcrt_CrtSetReportFile_impl(PyModuleDef *module, int type, int file); + +static PyObject * +msvcrt_CrtSetReportFile(PyModuleDef *module, PyObject *args) { - int type, file; + PyObject *return_value = NULL; + int type; + int file; + + if (!PyArg_ParseTuple(args, + "ii:CrtSetReportFile", + &type, &file)) + goto exit; + return_value = msvcrt_CrtSetReportFile_impl(module, type, file); + +exit: + return return_value; +} + +static PyObject * +msvcrt_CrtSetReportFile_impl(PyModuleDef *module, int type, int file) +/*[clinic end generated code: checksum=20f0d32045ebbfe2c2b9d9be732edf73b28111b0]*/ +{ _HFILE res; - if (!PyArg_ParseTuple(args, "ii", &type, &file)) - return NULL; res = _CrtSetReportFile(type, (_HFILE)file); return PyLong_FromLong((long)res); Py_INCREF(Py_None); return Py_None; } -static PyObject* -msvcrt_setreportmode(PyObject *self, PyObject *args) +/*[clinic input] +msvcrt.CrtSetReportMode + + type: int + mode: int + / + +Wrapper around _CrtSetReportMode. + +Only available on Debug builds. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_CrtSetReportMode__doc__, +"CrtSetReportMode(type, mode)\n" +"Wrapper around _CrtSetReportMode.\n" +"\n" +"Only available on Debug builds."); + +#define MSVCRT_CRTSETREPORTMODE_METHODDEF \ + {"CrtSetReportMode", (PyCFunction)msvcrt_CrtSetReportMode, METH_VARARGS, msvcrt_CrtSetReportMode__doc__}, + +static PyObject * +msvcrt_CrtSetReportMode_impl(PyModuleDef *module, int type, int mode); + +static PyObject * +msvcrt_CrtSetReportMode(PyModuleDef *module, PyObject *args) { - int type, mode; + PyObject *return_value = NULL; + int type; + int mode; + + if (!PyArg_ParseTuple(args, + "ii:CrtSetReportMode", + &type, &mode)) + goto exit; + return_value = msvcrt_CrtSetReportMode_impl(module, type, mode); + +exit: + return return_value; +} + +static PyObject * +msvcrt_CrtSetReportMode_impl(PyModuleDef *module, int type, int mode) +/*[clinic end generated code: checksum=9dba00697ee9cebcf09b6480b70061e1557d3e58]*/ +{ int res; - if (!PyArg_ParseTuple(args, "ii", &type, &mode)) - return NULL; res = _CrtSetReportMode(type, mode); if (res == -1) return PyErr_SetFromErrno(PyExc_IOError); return PyLong_FromLong(res); } -static PyObject* -msvcrt_seterrormode(PyObject *self, PyObject *args) +/*[clinic input] +msvcrt.set_error_mode + + mode: int + / + +Wrapper around _set_error_mode. + +Only available on Debug builds. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_set_error_mode__doc__, +"set_error_mode(mode)\n" +"Wrapper around _set_error_mode.\n" +"\n" +"Only available on Debug builds."); + +#define MSVCRT_SET_ERROR_MODE_METHODDEF \ + {"set_error_mode", (PyCFunction)msvcrt_set_error_mode, METH_VARARGS, msvcrt_set_error_mode__doc__}, + +static PyObject * +msvcrt_set_error_mode_impl(PyModuleDef *module, int mode); + +static PyObject * +msvcrt_set_error_mode(PyModuleDef *module, PyObject *args) { - int mode, res; + PyObject *return_value = NULL; + int mode; - if (!PyArg_ParseTuple(args, "i", &mode)) - return NULL; + if (!PyArg_ParseTuple(args, + "i:set_error_mode", + &mode)) + goto exit; + return_value = msvcrt_set_error_mode_impl(module, mode); + +exit: + return return_value; +} + +static PyObject * +msvcrt_set_error_mode_impl(PyModuleDef *module, int mode) +/*[clinic end generated code: checksum=36f643ce4325bbb7d1926351822327c91bb3e5b1]*/ +{ + int res; + res = _set_error_mode(mode); return PyLong_FromLong(res); } #endif -static PyObject* -seterrormode(PyObject *self, PyObject *args) +/*[clinic input] +msvcrt.SetErrorMode + + mode: unsigned_int(bitwise=True) + / + +Wrapper around SetErrorMode. +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_SetErrorMode__doc__, +"SetErrorMode(mode)\n" +"Wrapper around SetErrorMode."); + +#define MSVCRT_SETERRORMODE_METHODDEF \ + {"SetErrorMode", (PyCFunction)msvcrt_SetErrorMode, METH_VARARGS, msvcrt_SetErrorMode__doc__}, + +static PyObject * +msvcrt_SetErrorMode_impl(PyModuleDef *module, unsigned int mode); + +static PyObject * +msvcrt_SetErrorMode(PyModuleDef *module, PyObject *args) { - unsigned int mode, res; + PyObject *return_value = NULL; + unsigned int mode; - if (!PyArg_ParseTuple(args, "I", &mode)) - return NULL; + if (!PyArg_ParseTuple(args, + "I:SetErrorMode", + &mode)) + goto exit; + return_value = msvcrt_SetErrorMode_impl(module, mode); + +exit: + return return_value; +} + +static PyObject * +msvcrt_SetErrorMode_impl(PyModuleDef *module, unsigned int mode) +/*[clinic end generated code: checksum=3161391324bb6ea19d64dc3eea0dad6708421553]*/ +{ + unsigned int res; + res = SetErrorMode(mode); return PyLong_FromUnsignedLong(res); } @@ -425,27 +948,27 @@ /* List of functions exported by this module */ static struct PyMethodDef msvcrt_functions[] = { - {"heapmin", msvcrt_heapmin, METH_VARARGS, heapmin_doc}, - {"locking", msvcrt_locking, METH_VARARGS, locking_doc}, - {"setmode", msvcrt_setmode, METH_VARARGS, setmode_doc}, - {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS, open_osfhandle_doc}, - {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS, get_osfhandle_doc}, - {"kbhit", msvcrt_kbhit, METH_VARARGS, kbhit_doc}, - {"getch", msvcrt_getch, METH_VARARGS, getch_doc}, - {"getche", msvcrt_getche, METH_VARARGS, getche_doc}, - {"putch", msvcrt_putch, METH_VARARGS, putch_doc}, - {"ungetch", msvcrt_ungetch, METH_VARARGS, ungetch_doc}, - {"SetErrorMode", seterrormode, METH_VARARGS}, + MSVCRT_HEAPMIN_METHODDEF + MSVCRT_LOCKING_METHODDEF + MSVCRT_SETMODE_METHODDEF + MSVCRT_OPEN_OSFHANDLE_METHODDEF + MSVCRT_GET_OSFHANDLE_METHODDEF + MSVCRT_KBHIT_METHODDEF + MSVCRT_GETCH_METHODDEF + MSVCRT_GETCHE_METHODDEF + MSVCRT_PUTCH_METHODDEF + MSVCRT_UNGETCH_METHODDEF + MSVCRT_SETERRORMODE_METHODDEF #ifdef _DEBUG - {"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS}, - {"CrtSetReportMode", msvcrt_setreportmode, METH_VARARGS}, - {"set_error_mode", msvcrt_seterrormode, METH_VARARGS}, + MSVCRT_CRTSETREPORTFILE_METHODDEF + MSVCRT_CRTSETREPORTMODE_METHODDEF + MSVCRT_SET_ERROR_MODE_METHODDEF #endif #ifdef _WCONIO_DEFINED - {"getwch", msvcrt_getwch, METH_VARARGS, getwch_doc}, - {"getwche", msvcrt_getwche, METH_VARARGS, getwche_doc}, - {"putwch", msvcrt_putwch, METH_VARARGS, putwch_doc}, - {"ungetwch", msvcrt_ungetwch, METH_VARARGS, ungetwch_doc}, + MSVCRT_GETWCH_METHODDEF + MSVCRT_GETWCHE_METHODDEF + MSVCRT_PUTWCH_METHODDEF + MSVCRT_UNGETWCH_METHODDEF #endif {NULL, NULL} };