| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 1 | /********************************************************* | 
 | 2 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 3 |     msvcrtmodule.c | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 4 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 5 |     A Python interface to the Microsoft Visual C Runtime | 
 | 6 |     Library, providing access to those non-portable, but | 
 | 7 |     still useful routines. | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 8 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 9 |     Only ever compiled with an MS compiler, so no attempt | 
 | 10 |     has been made to avoid MS language extensions, etc... | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 11 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 12 |     This may only work on NT or 95... | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 13 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 14 |     Author: Mark Hammond and Guido van Rossum. | 
 | 15 |     Maintenance: Guido van Rossum. | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 16 |  | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 17 | ***********************************************************/ | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 18 |  | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 19 | #include "Python.h" | 
 | 20 | #include "malloc.h" | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 21 | #include <io.h> | 
 | 22 | #include <conio.h> | 
 | 23 | #include <sys/locking.h> | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 24 | #include <crtdbg.h> | 
 | 25 | #include <windows.h> | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 26 |  | 
| Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 27 | #ifdef _MSC_VER | 
| Martin v. Löwis | 3afc62e | 2010-02-18 16:27:43 +0000 | [diff] [blame] | 28 | #if _MSC_VER >= 1500 && _MSC_VER < 1600 | 
| Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 29 | #include <crtassem.h> | 
| Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 30 | #elif _MSC_VER >= 1600 | 
 | 31 | #include <crtversion.h> | 
| Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 32 | #endif | 
 | 33 | #endif | 
 | 34 |  | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 35 | // Force the malloc heap to clean itself up, and free unused blocks | 
 | 36 | // back to the OS.  (According to the docs, only works on NT.) | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 37 | static PyObject * | 
 | 38 | msvcrt_heapmin(PyObject *self, PyObject *args) | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 39 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 40 |     if (!PyArg_ParseTuple(args, ":heapmin")) | 
 | 41 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 42 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 43 |     if (_heapmin() != 0) | 
 | 44 |         return PyErr_SetFromErrno(PyExc_IOError); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 45 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 46 |     Py_INCREF(Py_None); | 
 | 47 |     return Py_None; | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 48 | } | 
 | 49 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 50 | PyDoc_STRVAR(heapmin_doc, | 
 | 51 | "heapmin() -> None\n\ | 
 | 52 | \n\ | 
 | 53 | Force the malloc() heap to clean itself up and return unused blocks\n\ | 
 | 54 | to the operating system. On failure, this raises IOError."); | 
 | 55 |  | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 56 | // Perform locking operations on a C runtime file descriptor. | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 57 | static PyObject * | 
 | 58 | msvcrt_locking(PyObject *self, PyObject *args) | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 59 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 60 |     int fd; | 
 | 61 |     int mode; | 
 | 62 |     long nbytes; | 
 | 63 |     int err; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 64 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 65 |     if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes)) | 
 | 66 |         return NULL; | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 67 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 68 |     Py_BEGIN_ALLOW_THREADS | 
 | 69 |     err = _locking(fd, mode, nbytes); | 
 | 70 |     Py_END_ALLOW_THREADS | 
 | 71 |     if (err != 0) | 
 | 72 |         return PyErr_SetFromErrno(PyExc_IOError); | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 73 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 74 |     Py_INCREF(Py_None); | 
 | 75 |     return Py_None; | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 76 | } | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 77 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 78 | PyDoc_STRVAR(locking_doc, | 
 | 79 | "locking(fd, mode, nbytes) -> None\n\ | 
 | 80 | \n\ | 
 | 81 | Lock part of a file based on file descriptor fd from the C runtime.\n\ | 
 | 82 | Raises IOError on failure. The locked region of the file extends from\n\ | 
 | 83 | the current file position for nbytes bytes, and may continue beyond\n\ | 
 | 84 | the end of the file. mode must be one of the LK_* constants listed\n\ | 
 | 85 | below. Multiple regions in a file may be locked at the same time, but\n\ | 
 | 86 | may not overlap. Adjacent regions are not merged; they must be unlocked\n\ | 
 | 87 | individually."); | 
 | 88 |  | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 89 | // Set the file translation mode for a C runtime file descriptor. | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 90 | static PyObject * | 
 | 91 | msvcrt_setmode(PyObject *self, PyObject *args) | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 92 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 93 |     int fd; | 
 | 94 |     int flags; | 
 | 95 |     if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags)) | 
 | 96 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 97 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 98 |     flags = _setmode(fd, flags); | 
 | 99 |     if (flags == -1) | 
 | 100 |         return PyErr_SetFromErrno(PyExc_IOError); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 101 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 102 |     return PyLong_FromLong(flags); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 103 | } | 
 | 104 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 105 | PyDoc_STRVAR(setmode_doc, | 
 | 106 | "setmode(fd, mode) -> Previous mode\n\ | 
 | 107 | \n\ | 
 | 108 | Set the line-end translation mode for the file descriptor fd. To set\n\ | 
 | 109 | it to text mode, flags should be os.O_TEXT; for binary, it should be\n\ | 
 | 110 | os.O_BINARY."); | 
 | 111 |  | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 112 | // Convert an OS file handle to a C runtime file descriptor. | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 113 | static PyObject * | 
 | 114 | msvcrt_open_osfhandle(PyObject *self, PyObject *args) | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 115 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 116 |     long handle; | 
 | 117 |     int flags; | 
 | 118 |     int fd; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 119 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 120 |     if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags)) | 
 | 121 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 122 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 123 |     fd = _open_osfhandle(handle, flags); | 
 | 124 |     if (fd == -1) | 
 | 125 |         return PyErr_SetFromErrno(PyExc_IOError); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 126 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 127 |     return PyLong_FromLong(fd); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 128 | } | 
 | 129 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 130 | PyDoc_STRVAR(open_osfhandle_doc, | 
 | 131 | "open_osfhandle(handle, flags) -> file descriptor\n\ | 
 | 132 | \n\ | 
 | 133 | Create a C runtime file descriptor from the file handle handle. The\n\ | 
 | 134 | flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n\ | 
 | 135 | and os.O_TEXT. The returned file descriptor may be used as a parameter\n\ | 
 | 136 | to os.fdopen() to create a file object."); | 
 | 137 |  | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 138 | // Convert a C runtime file descriptor to an OS file handle. | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 139 | static PyObject * | 
 | 140 | msvcrt_get_osfhandle(PyObject *self, PyObject *args) | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 141 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 142 |     int fd; | 
 | 143 |     Py_intptr_t handle; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 144 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 145 |     if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) | 
 | 146 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 147 |  | 
| Antoine Pitrou | 0049249 | 2010-09-04 20:53:29 +0000 | [diff] [blame] | 148 |     if (!_PyVerify_fd(fd)) | 
 | 149 |         return PyErr_SetFromErrno(PyExc_IOError); | 
 | 150 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 151 |     handle = _get_osfhandle(fd); | 
 | 152 |     if (handle == -1) | 
 | 153 |         return PyErr_SetFromErrno(PyExc_IOError); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 154 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 155 |     /* technically 'handle' is not a pointer, but a integer as | 
 | 156 |        large as a pointer, Python's *VoidPtr interface is the | 
 | 157 |        most appropriate here */ | 
 | 158 |     return PyLong_FromVoidPtr((void*)handle); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 159 | } | 
 | 160 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 161 | PyDoc_STRVAR(get_osfhandle_doc, | 
 | 162 | "get_osfhandle(fd) -> file handle\n\ | 
 | 163 | \n\ | 
 | 164 | Return the file handle for the file descriptor fd. Raises IOError\n\ | 
 | 165 | if fd is not recognized."); | 
 | 166 |  | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 167 | /* Console I/O */ | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 168 |  | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 169 | static PyObject * | 
 | 170 | msvcrt_kbhit(PyObject *self, PyObject *args) | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 171 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 172 |     int ok; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 173 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 174 |     if (!PyArg_ParseTuple(args, ":kbhit")) | 
 | 175 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 176 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 177 |     ok = _kbhit(); | 
 | 178 |     return PyLong_FromLong(ok); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 179 | } | 
 | 180 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 181 | PyDoc_STRVAR(kbhit_doc, | 
 | 182 | "kbhit() -> bool\n\ | 
 | 183 | \n\ | 
 | 184 | Return true if a keypress is waiting to be read."); | 
 | 185 |  | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 186 | static PyObject * | 
 | 187 | msvcrt_getch(PyObject *self, PyObject *args) | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 188 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 189 |     int ch; | 
 | 190 |     char s[1]; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 191 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 192 |     if (!PyArg_ParseTuple(args, ":getch")) | 
 | 193 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 194 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 195 |     Py_BEGIN_ALLOW_THREADS | 
 | 196 |     ch = _getch(); | 
 | 197 |     Py_END_ALLOW_THREADS | 
 | 198 |     s[0] = ch; | 
 | 199 |     return PyBytes_FromStringAndSize(s, 1); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 200 | } | 
 | 201 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 202 | PyDoc_STRVAR(getch_doc, | 
 | 203 | "getch() -> key character\n\ | 
 | 204 | \n\ | 
| Brian Curtin | 8790a07 | 2010-08-24 05:20:30 +0000 | [diff] [blame] | 205 | Read a keypress and return the resulting character as a byte string.\n\ | 
 | 206 | Nothing is echoed to the console. This call will block if a keypress is\n\ | 
 | 207 | not already available, but will not wait for Enter to be pressed. If the\n\ | 
 | 208 | pressed key was a special function key, this will return '\\000' or\n\ | 
 | 209 | '\\xe0'; the next call will return the keycode. The Control-C keypress\n\ | 
 | 210 | cannot be read with this function."); | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 211 |  | 
| Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 212 | #ifdef _WCONIO_DEFINED | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 213 | static PyObject * | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 214 | msvcrt_getwch(PyObject *self, PyObject *args) | 
 | 215 | { | 
| Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 216 |     wchar_t ch; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 217 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 218 |     if (!PyArg_ParseTuple(args, ":getwch")) | 
 | 219 |         return NULL; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 220 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 221 |     Py_BEGIN_ALLOW_THREADS | 
 | 222 |     ch = _getwch(); | 
 | 223 |     Py_END_ALLOW_THREADS | 
| Martin v. Löwis | d63a3b8 | 2011-09-28 07:41:54 +0200 | [diff] [blame] | 224 |     return PyUnicode_FromOrdinal(ch); | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 225 | } | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 226 |  | 
 | 227 | PyDoc_STRVAR(getwch_doc, | 
 | 228 | "getwch() -> Unicode key character\n\ | 
 | 229 | \n\ | 
 | 230 | Wide char variant of getch(), returning a Unicode value."); | 
| Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 231 | #endif | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 232 |  | 
 | 233 | static PyObject * | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 234 | msvcrt_getche(PyObject *self, PyObject *args) | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 235 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 236 |     int ch; | 
 | 237 |     char s[1]; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 238 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 239 |     if (!PyArg_ParseTuple(args, ":getche")) | 
 | 240 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 241 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 242 |     Py_BEGIN_ALLOW_THREADS | 
 | 243 |     ch = _getche(); | 
 | 244 |     Py_END_ALLOW_THREADS | 
 | 245 |     s[0] = ch; | 
 | 246 |     return PyBytes_FromStringAndSize(s, 1); | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 247 | } | 
 | 248 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 249 | PyDoc_STRVAR(getche_doc, | 
 | 250 | "getche() -> key character\n\ | 
 | 251 | \n\ | 
 | 252 | Similar to getch(), but the keypress will be echoed if it represents\n\ | 
 | 253 | a printable character."); | 
 | 254 |  | 
| Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 255 | #ifdef _WCONIO_DEFINED | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 256 | static PyObject * | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 257 | msvcrt_getwche(PyObject *self, PyObject *args) | 
 | 258 | { | 
| Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 259 |     wchar_t ch; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 260 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 261 |     if (!PyArg_ParseTuple(args, ":getwche")) | 
 | 262 |         return NULL; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 263 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 264 |     Py_BEGIN_ALLOW_THREADS | 
 | 265 |     ch = _getwche(); | 
 | 266 |     Py_END_ALLOW_THREADS | 
| Martin v. Löwis | d63a3b8 | 2011-09-28 07:41:54 +0200 | [diff] [blame] | 267 |     return PyUnicode_FromOrdinal(ch); | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 268 | } | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 269 |  | 
 | 270 | PyDoc_STRVAR(getwche_doc, | 
 | 271 | "getwche() -> Unicode key character\n\ | 
 | 272 | \n\ | 
 | 273 | Wide char variant of getche(), returning a Unicode value."); | 
| Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 274 | #endif | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 275 |  | 
 | 276 | static PyObject * | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 277 | msvcrt_putch(PyObject *self, PyObject *args) | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 278 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 279 |     char ch; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 280 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 281 |     if (!PyArg_ParseTuple(args, "c:putch", &ch)) | 
 | 282 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 283 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 284 |     _putch(ch); | 
 | 285 |     Py_INCREF(Py_None); | 
 | 286 |     return Py_None; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 287 | } | 
 | 288 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 289 | PyDoc_STRVAR(putch_doc, | 
 | 290 | "putch(char) -> None\n\ | 
 | 291 | \n\ | 
| Brian Curtin | 8790a07 | 2010-08-24 05:20:30 +0000 | [diff] [blame] | 292 | Print the byte string char to the console without buffering."); | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 293 |  | 
| Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 294 | #ifdef _WCONIO_DEFINED | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 295 | static PyObject * | 
 | 296 | msvcrt_putwch(PyObject *self, PyObject *args) | 
 | 297 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 298 |     int ch; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 299 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 300 |     if (!PyArg_ParseTuple(args, "C:putwch", &ch)) | 
 | 301 |         return NULL; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 302 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 303 |     _putwch(ch); | 
 | 304 |     Py_RETURN_NONE; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 305 |  | 
 | 306 | } | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 307 |  | 
 | 308 | PyDoc_STRVAR(putwch_doc, | 
 | 309 | "putwch(unicode_char) -> None\n\ | 
 | 310 | \n\ | 
 | 311 | Wide char variant of putch(), accepting a Unicode value."); | 
| Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 312 | #endif | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 313 |  | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 314 | static PyObject * | 
 | 315 | msvcrt_ungetch(PyObject *self, PyObject *args) | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 316 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 317 |     char ch; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 318 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 319 |     if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) | 
 | 320 |         return NULL; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 321 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 322 |     if (_ungetch(ch) == EOF) | 
 | 323 |         return PyErr_SetFromErrno(PyExc_IOError); | 
 | 324 |     Py_INCREF(Py_None); | 
 | 325 |     return Py_None; | 
| Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 326 | } | 
 | 327 |  | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 328 | PyDoc_STRVAR(ungetch_doc, | 
 | 329 | "ungetch(char) -> None\n\ | 
 | 330 | \n\ | 
| Brian Curtin | 8790a07 | 2010-08-24 05:20:30 +0000 | [diff] [blame] | 331 | Cause the byte string char to be \"pushed back\" into the\n\ | 
 | 332 | console buffer; it will be the next character read by\n\ | 
 | 333 | getch() or getche()."); | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 334 |  | 
| Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 335 | #ifdef _WCONIO_DEFINED | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 336 | static PyObject * | 
 | 337 | msvcrt_ungetwch(PyObject *self, PyObject *args) | 
 | 338 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 339 |     int ch; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 340 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 341 |     if (!PyArg_ParseTuple(args, "C:ungetwch", &ch)) | 
 | 342 |         return NULL; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 343 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 344 |     if (_ungetwch(ch) == WEOF) | 
 | 345 |         return PyErr_SetFromErrno(PyExc_IOError); | 
 | 346 |     Py_INCREF(Py_None); | 
 | 347 |     return Py_None; | 
| Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 348 | } | 
| Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 349 |  | 
 | 350 | PyDoc_STRVAR(ungetwch_doc, | 
 | 351 | "ungetwch(unicode_char) -> None\n\ | 
 | 352 | \n\ | 
 | 353 | Wide char variant of ungetch(), accepting a Unicode value."); | 
| Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 354 | #endif | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 355 |  | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 356 | static void | 
 | 357 | insertint(PyObject *d, char *name, int value) | 
 | 358 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 359 |     PyObject *v = PyLong_FromLong((long) value); | 
 | 360 |     if (v == NULL) { | 
 | 361 |         /* Don't bother reporting this error */ | 
 | 362 |         PyErr_Clear(); | 
 | 363 |     } | 
 | 364 |     else { | 
 | 365 |         PyDict_SetItemString(d, name, v); | 
 | 366 |         Py_DECREF(v); | 
 | 367 |     } | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 368 | } | 
 | 369 |  | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 370 | #ifdef _DEBUG | 
 | 371 |  | 
 | 372 | static PyObject* | 
 | 373 | msvcrt_setreportfile(PyObject *self, PyObject *args) | 
 | 374 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 375 |     int type, file; | 
 | 376 |     _HFILE res; | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 377 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 378 |     if (!PyArg_ParseTuple(args, "ii", &type, &file)) | 
 | 379 |         return NULL; | 
 | 380 |     res = _CrtSetReportFile(type, (_HFILE)file); | 
 | 381 |     return PyLong_FromLong((long)res); | 
 | 382 |     Py_INCREF(Py_None); | 
 | 383 |     return Py_None; | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 384 | } | 
 | 385 |  | 
 | 386 | static PyObject* | 
 | 387 | msvcrt_setreportmode(PyObject *self, PyObject *args) | 
 | 388 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 389 |     int type, mode; | 
 | 390 |     int res; | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 391 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 392 |     if (!PyArg_ParseTuple(args, "ii", &type, &mode)) | 
 | 393 |         return NULL; | 
 | 394 |     res = _CrtSetReportMode(type, mode); | 
 | 395 |     if (res == -1) | 
 | 396 |         return PyErr_SetFromErrno(PyExc_IOError); | 
 | 397 |     return PyLong_FromLong(res); | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 398 | } | 
 | 399 |  | 
 | 400 | static PyObject* | 
 | 401 | msvcrt_seterrormode(PyObject *self, PyObject *args) | 
 | 402 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 403 |     int mode, res; | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 404 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 405 |     if (!PyArg_ParseTuple(args, "i", &mode)) | 
 | 406 |         return NULL; | 
 | 407 |     res = _set_error_mode(mode); | 
 | 408 |     return PyLong_FromLong(res); | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 409 | } | 
 | 410 |  | 
 | 411 | #endif | 
 | 412 |  | 
 | 413 | static PyObject* | 
 | 414 | seterrormode(PyObject *self, PyObject *args) | 
 | 415 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 416 |     unsigned int mode, res; | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 417 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 418 |     if (!PyArg_ParseTuple(args, "I", &mode)) | 
 | 419 |         return NULL; | 
 | 420 |     res = SetErrorMode(mode); | 
 | 421 |     return PyLong_FromUnsignedLong(res); | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 422 | } | 
 | 423 |  | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 424 |  | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 425 | /* List of functions exported by this module */ | 
 | 426 | static struct PyMethodDef msvcrt_functions[] = { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 427 |     {"heapmin",                 msvcrt_heapmin, METH_VARARGS, heapmin_doc}, | 
 | 428 |     {"locking",             msvcrt_locking, METH_VARARGS, locking_doc}, | 
 | 429 |     {"setmode",                 msvcrt_setmode, METH_VARARGS, setmode_doc}, | 
 | 430 |     {"open_osfhandle",          msvcrt_open_osfhandle, METH_VARARGS, open_osfhandle_doc}, | 
 | 431 |     {"get_osfhandle",           msvcrt_get_osfhandle, METH_VARARGS, get_osfhandle_doc}, | 
 | 432 |     {"kbhit",                   msvcrt_kbhit, METH_VARARGS, kbhit_doc}, | 
 | 433 |     {"getch",                   msvcrt_getch, METH_VARARGS, getch_doc}, | 
 | 434 |     {"getche",                  msvcrt_getche, METH_VARARGS, getche_doc}, | 
 | 435 |     {"putch",                   msvcrt_putch, METH_VARARGS, putch_doc}, | 
 | 436 |     {"ungetch",                 msvcrt_ungetch, METH_VARARGS, ungetch_doc}, | 
 | 437 |     {"SetErrorMode",            seterrormode, METH_VARARGS}, | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 438 | #ifdef _DEBUG | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 439 |     {"CrtSetReportFile",        msvcrt_setreportfile, METH_VARARGS}, | 
 | 440 |     {"CrtSetReportMode",        msvcrt_setreportmode, METH_VARARGS}, | 
 | 441 |     {"set_error_mode",          msvcrt_seterrormode, METH_VARARGS}, | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 442 | #endif | 
| Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame] | 443 | #ifdef _WCONIO_DEFINED | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 444 |     {"getwch",                  msvcrt_getwch, METH_VARARGS, getwch_doc}, | 
 | 445 |     {"getwche",                 msvcrt_getwche, METH_VARARGS, getwche_doc}, | 
 | 446 |     {"putwch",                  msvcrt_putwch, METH_VARARGS, putwch_doc}, | 
 | 447 |     {"ungetwch",                msvcrt_ungetwch, METH_VARARGS, ungetwch_doc}, | 
| Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 448 | #endif | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 449 |     {NULL,                      NULL} | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 450 | }; | 
 | 451 |  | 
| Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 452 |  | 
 | 453 | static struct PyModuleDef msvcrtmodule = { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 454 |     PyModuleDef_HEAD_INIT, | 
 | 455 |     "msvcrt", | 
 | 456 |     NULL, | 
 | 457 |     -1, | 
 | 458 |     msvcrt_functions, | 
 | 459 |     NULL, | 
 | 460 |     NULL, | 
 | 461 |     NULL, | 
 | 462 |     NULL | 
| Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 463 | }; | 
 | 464 |  | 
| Thomas Heller | a18331d | 2004-07-28 20:02:52 +0000 | [diff] [blame] | 465 | PyMODINIT_FUNC | 
| Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 466 | PyInit_msvcrt(void) | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 467 | { | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 468 |     int st; | 
| Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 469 |     PyObject *d, *version; | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 470 |     PyObject *m = PyModule_Create(&msvcrtmodule); | 
 | 471 |     if (m == NULL) | 
 | 472 |         return NULL; | 
 | 473 |     d = PyModule_GetDict(m); | 
| Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 474 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 475 |     /* constants for the locking() function's mode argument */ | 
 | 476 |     insertint(d, "LK_LOCK", _LK_LOCK); | 
 | 477 |     insertint(d, "LK_NBLCK", _LK_NBLCK); | 
 | 478 |     insertint(d, "LK_NBRLCK", _LK_NBRLCK); | 
 | 479 |     insertint(d, "LK_RLCK", _LK_RLCK); | 
 | 480 |     insertint(d, "LK_UNLCK", _LK_UNLCK); | 
 | 481 |     insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS); | 
 | 482 |     insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT); | 
 | 483 |     insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX); | 
 | 484 |     insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX); | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 485 | #ifdef _DEBUG | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 486 |     insertint(d, "CRT_WARN", _CRT_WARN); | 
 | 487 |     insertint(d, "CRT_ERROR", _CRT_ERROR); | 
 | 488 |     insertint(d, "CRT_ASSERT", _CRT_ASSERT); | 
 | 489 |     insertint(d, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG); | 
 | 490 |     insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE); | 
 | 491 |     insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW); | 
 | 492 |     insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE); | 
 | 493 |     insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR); | 
 | 494 |     insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT); | 
 | 495 |     insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE); | 
| Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 496 | #endif | 
| Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 497 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 498 |     /* constants for the crt versions */ | 
| Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 499 |     (void)st; | 
| Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 500 | #ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 501 |     st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN", | 
 | 502 |                                     _VC_ASSEMBLY_PUBLICKEYTOKEN); | 
 | 503 |     if (st < 0) return NULL; | 
| Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 504 | #endif | 
 | 505 | #ifdef _CRT_ASSEMBLY_VERSION | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 506 |     st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION", | 
 | 507 |                                     _CRT_ASSEMBLY_VERSION); | 
 | 508 |     if (st < 0) return NULL; | 
| Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 509 | #endif | 
 | 510 | #ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 511 |     st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX", | 
 | 512 |                                     __LIBRARIES_ASSEMBLY_NAME_PREFIX); | 
 | 513 |     if (st < 0) return NULL; | 
| Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 514 | #endif | 
 | 515 |  | 
| Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 516 |     /* constants for the 2010 crt versions */ | 
 | 517 | #if defined(_VC_CRT_MAJOR_VERSION) && defined (_VC_CRT_MINOR_VERSION) && defined(_VC_CRT_BUILD_VERSION) && defined(_VC_CRT_RBUILD_VERSION) | 
 | 518 |     version = PyUnicode_FromFormat("%d.%d.%d.%d", _VC_CRT_MAJOR_VERSION, | 
 | 519 |                                                   _VC_CRT_MINOR_VERSION, | 
 | 520 |                                                   _VC_CRT_BUILD_VERSION, | 
 | 521 |                                                   _VC_CRT_RBUILD_VERSION); | 
 | 522 |     st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version); | 
 | 523 |     if (st < 0) return NULL; | 
 | 524 | #endif | 
 | 525 |  | 
| Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 526 |     return m; | 
| Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 527 | } |