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