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 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 35 | /*[python input] |
Benjamin Peterson | ca47063 | 2016-09-06 13:47:26 -0700 | [diff] [blame] | 36 | class intptr_t_converter(CConverter): |
| 37 | type = 'intptr_t' |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 38 | format_unit = '"_Py_PARSE_INTPTR"' |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 39 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 40 | class handle_return_converter(long_return_converter): |
Benjamin Peterson | ca47063 | 2016-09-06 13:47:26 -0700 | [diff] [blame] | 41 | type = 'intptr_t' |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 42 | cast = '(void *)' |
| 43 | conversion_fn = 'PyLong_FromVoidPtr' |
| 44 | |
| 45 | class byte_char_return_converter(CReturnConverter): |
| 46 | type = 'int' |
| 47 | |
| 48 | def render(self, function, data): |
| 49 | data.declarations.append('char s[1];') |
| 50 | data.return_value = 's[0]' |
| 51 | data.return_conversion.append( |
| 52 | 'return_value = PyBytes_FromStringAndSize(s, 1);\n') |
| 53 | |
| 54 | class wchar_t_return_converter(CReturnConverter): |
| 55 | type = 'wchar_t' |
| 56 | |
| 57 | def render(self, function, data): |
| 58 | self.declare(data) |
| 59 | data.return_conversion.append( |
| 60 | 'return_value = PyUnicode_FromOrdinal(_return_value);\n') |
| 61 | [python start generated code]*/ |
Benjamin Peterson | cc85449 | 2016-09-08 09:29:11 -0700 | [diff] [blame] | 62 | /*[python end generated code: output=da39a3ee5e6b4b0d input=b59f1663dba11997]*/ |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 63 | |
| 64 | /*[clinic input] |
| 65 | module msvcrt |
| 66 | [clinic start generated code]*/ |
| 67 | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=f31a87a783d036cd]*/ |
| 68 | |
| 69 | #include "clinic/msvcrtmodule.c.h" |
| 70 | |
| 71 | /*[clinic input] |
| 72 | msvcrt.heapmin |
| 73 | |
| 74 | Minimize the malloc() heap. |
| 75 | |
| 76 | Force the malloc() heap to clean itself up and return unused blocks |
| 77 | to the operating system. On failure, this raises OSError. |
| 78 | [clinic start generated code]*/ |
| 79 | |
| 80 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 81 | msvcrt_heapmin_impl(PyObject *module) |
| 82 | /*[clinic end generated code: output=1ba00f344782dc19 input=82e1771d21bde2d8]*/ |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 83 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 84 | if (_heapmin() != 0) |
| 85 | return PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 86 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 87 | Py_RETURN_NONE; |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 88 | } |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 89 | /*[clinic input] |
| 90 | msvcrt.locking |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 91 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 92 | fd: int |
| 93 | mode: int |
| 94 | nbytes: long |
| 95 | / |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 96 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 97 | Lock part of a file based on file descriptor fd from the C runtime. |
| 98 | |
| 99 | Raises IOError on failure. The locked region of the file extends from |
| 100 | the current file position for nbytes bytes, and may continue beyond |
| 101 | the end of the file. mode must be one of the LK_* constants listed |
| 102 | below. Multiple regions in a file may be locked at the same time, but |
| 103 | may not overlap. Adjacent regions are not merged; they must be unlocked |
| 104 | individually. |
| 105 | [clinic start generated code]*/ |
| 106 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 107 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 108 | msvcrt_locking_impl(PyObject *module, int fd, int mode, long nbytes) |
| 109 | /*[clinic end generated code: output=a4a90deca9785a03 input=d9f13f0f6a713ba7]*/ |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 110 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 111 | int err; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 112 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 113 | Py_BEGIN_ALLOW_THREADS |
| 114 | err = _locking(fd, mode, nbytes); |
| 115 | Py_END_ALLOW_THREADS |
| 116 | if (err != 0) |
| 117 | return PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 118 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 119 | Py_RETURN_NONE; |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 120 | } |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 121 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 122 | /*[clinic input] |
| 123 | msvcrt.setmode -> long |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 124 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 125 | fd: int |
| 126 | mode as flags: int |
| 127 | / |
| 128 | |
| 129 | Set the line-end translation mode for the file descriptor fd. |
| 130 | |
| 131 | To set it to text mode, flags should be os.O_TEXT; for binary, it |
| 132 | should be os.O_BINARY. |
| 133 | |
| 134 | Return value is the previous mode. |
| 135 | [clinic start generated code]*/ |
| 136 | |
| 137 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 138 | msvcrt_setmode_impl(PyObject *module, int fd, int flags) |
| 139 | /*[clinic end generated code: output=24a9be5ea07ccb9b input=76e7c01f6b137f75]*/ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 140 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 141 | flags = _setmode(fd, flags); |
| 142 | if (flags == -1) |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 143 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 144 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 145 | return flags; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 148 | /*[clinic input] |
| 149 | msvcrt.open_osfhandle -> long |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 150 | |
Benjamin Peterson | ca47063 | 2016-09-06 13:47:26 -0700 | [diff] [blame] | 151 | handle: intptr_t |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 152 | flags: int |
| 153 | / |
| 154 | |
| 155 | Create a C runtime file descriptor from the file handle handle. |
| 156 | |
| 157 | The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY, |
| 158 | and os.O_TEXT. The returned file descriptor may be used as a parameter |
| 159 | to os.fdopen() to create a file object. |
| 160 | [clinic start generated code]*/ |
| 161 | |
| 162 | static long |
Benjamin Peterson | ca47063 | 2016-09-06 13:47:26 -0700 | [diff] [blame] | 163 | msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags) |
Benjamin Peterson | cc85449 | 2016-09-08 09:29:11 -0700 | [diff] [blame] | 164 | /*[clinic end generated code: output=cede871bf939d6e3 input=cb2108bbea84514e]*/ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 165 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 166 | int fd; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 167 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 168 | fd = _open_osfhandle(handle, flags); |
| 169 | if (fd == -1) |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 170 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 171 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 172 | return fd; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 175 | /*[clinic input] |
| 176 | msvcrt.get_osfhandle -> handle |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 177 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 178 | fd: int |
| 179 | / |
| 180 | |
| 181 | Return the file handle for the file descriptor fd. |
| 182 | |
| 183 | Raises IOError if fd is not recognized. |
| 184 | [clinic start generated code]*/ |
| 185 | |
Benjamin Peterson | ca47063 | 2016-09-06 13:47:26 -0700 | [diff] [blame] | 186 | static intptr_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 187 | msvcrt_get_osfhandle_impl(PyObject *module, int fd) |
Benjamin Peterson | cc85449 | 2016-09-08 09:29:11 -0700 | [diff] [blame] | 188 | /*[clinic end generated code: output=7ce761dd0de2b503 input=c7d18d02c8017ec1]*/ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 189 | { |
Benjamin Peterson | ca47063 | 2016-09-06 13:47:26 -0700 | [diff] [blame] | 190 | intptr_t handle = -1; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 191 | |
Steve Dower | 8fc8980 | 2015-04-12 00:26:27 -0400 | [diff] [blame] | 192 | _Py_BEGIN_SUPPRESS_IPH |
Steve Dower | 940f33a | 2016-09-08 11:21:54 -0700 | [diff] [blame] | 193 | handle = _get_osfhandle(fd); |
Steve Dower | 8fc8980 | 2015-04-12 00:26:27 -0400 | [diff] [blame] | 194 | _Py_END_SUPPRESS_IPH |
Steve Dower | 940f33a | 2016-09-08 11:21:54 -0700 | [diff] [blame] | 195 | if (handle == -1) |
| 196 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 197 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 198 | return handle; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* Console I/O */ |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 202 | /*[clinic input] |
| 203 | msvcrt.kbhit -> long |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 204 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 205 | Return true if a keypress is waiting to be read. |
| 206 | [clinic start generated code]*/ |
| 207 | |
| 208 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 209 | msvcrt_kbhit_impl(PyObject *module) |
| 210 | /*[clinic end generated code: output=940dfce6587c1890 input=e70d678a5c2f6acc]*/ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 211 | { |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 212 | return _kbhit(); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 215 | /*[clinic input] |
| 216 | msvcrt.getch -> byte_char |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 217 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 218 | Read a keypress and return the resulting character as a byte string. |
| 219 | |
| 220 | Nothing is echoed to the console. This call will block if a keypress is |
| 221 | not already available, but will not wait for Enter to be pressed. If the |
| 222 | pressed key was a special function key, this will return '\000' or |
| 223 | '\xe0'; the next call will return the keycode. The Control-C keypress |
| 224 | cannot be read with this function. |
| 225 | [clinic start generated code]*/ |
| 226 | |
| 227 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 228 | msvcrt_getch_impl(PyObject *module) |
| 229 | /*[clinic end generated code: output=a4e51f0565064a7d input=37a40cf0ed0d1153]*/ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 230 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 231 | int ch; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 232 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 233 | Py_BEGIN_ALLOW_THREADS |
| 234 | ch = _getch(); |
| 235 | Py_END_ALLOW_THREADS |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 236 | return ch; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 239 | /*[clinic input] |
| 240 | msvcrt.getwch -> wchar_t |
| 241 | |
| 242 | Wide char variant of getch(), returning a Unicode value. |
| 243 | [clinic start generated code]*/ |
| 244 | |
| 245 | static wchar_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 246 | msvcrt_getwch_impl(PyObject *module) |
| 247 | /*[clinic end generated code: output=be9937494e22f007 input=27b3dec8ad823d7c]*/ |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 248 | { |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 249 | wchar_t ch; |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 250 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 251 | Py_BEGIN_ALLOW_THREADS |
| 252 | ch = _getwch(); |
| 253 | Py_END_ALLOW_THREADS |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 254 | return ch; |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 255 | } |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 256 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 257 | /*[clinic input] |
| 258 | msvcrt.getche -> byte_char |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 259 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 260 | Similar to getch(), but the keypress will be echoed if possible. |
| 261 | [clinic start generated code]*/ |
| 262 | |
| 263 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 264 | msvcrt_getche_impl(PyObject *module) |
| 265 | /*[clinic end generated code: output=d8f7db4fd2990401 input=43311ade9ed4a9c0]*/ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 266 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 267 | int ch; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 268 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 269 | Py_BEGIN_ALLOW_THREADS |
| 270 | ch = _getche(); |
| 271 | Py_END_ALLOW_THREADS |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 272 | return ch; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 275 | /*[clinic input] |
| 276 | msvcrt.getwche -> wchar_t |
| 277 | |
| 278 | Wide char variant of getche(), returning a Unicode value. |
| 279 | [clinic start generated code]*/ |
| 280 | |
| 281 | static wchar_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 282 | msvcrt_getwche_impl(PyObject *module) |
| 283 | /*[clinic end generated code: output=d0dae5ba3829d596 input=49337d59d1a591f8]*/ |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 284 | { |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 285 | wchar_t ch; |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 286 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 287 | Py_BEGIN_ALLOW_THREADS |
| 288 | ch = _getwche(); |
| 289 | Py_END_ALLOW_THREADS |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 290 | return ch; |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 291 | } |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 292 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 293 | /*[clinic input] |
| 294 | msvcrt.putch |
| 295 | |
| 296 | char: char |
| 297 | / |
| 298 | |
| 299 | Print the byte string char to the console without buffering. |
| 300 | [clinic start generated code]*/ |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 301 | |
| 302 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 303 | msvcrt_putch_impl(PyObject *module, char char_value) |
| 304 | /*[clinic end generated code: output=92ec9b81012d8f60 input=ec078dd10cb054d6]*/ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 305 | { |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 306 | _putch(char_value); |
| 307 | Py_RETURN_NONE; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 310 | /*[clinic input] |
| 311 | msvcrt.putwch |
| 312 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 313 | unicode_char: int(accept={str}) |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 314 | / |
| 315 | |
| 316 | Wide char variant of putch(), accepting a Unicode value. |
| 317 | [clinic start generated code]*/ |
| 318 | |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 319 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 320 | msvcrt_putwch_impl(PyObject *module, int unicode_char) |
| 321 | /*[clinic end generated code: output=a3bd1a8951d28eee input=996ccd0bbcbac4c3]*/ |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 322 | { |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 323 | _putwch(unicode_char); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 324 | Py_RETURN_NONE; |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 325 | |
| 326 | } |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 327 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 328 | /*[clinic input] |
| 329 | msvcrt.ungetch |
| 330 | |
| 331 | char: char |
| 332 | / |
| 333 | |
| 334 | Opposite of getch. |
| 335 | |
| 336 | Cause the byte string char to be "pushed back" into the |
| 337 | console buffer; it will be the next character read by |
| 338 | getch() or getche(). |
| 339 | [clinic start generated code]*/ |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 340 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 341 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 342 | msvcrt_ungetch_impl(PyObject *module, char char_value) |
| 343 | /*[clinic end generated code: output=c6942a0efa119000 input=22f07ee9001bbf0f]*/ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 344 | { |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 345 | if (_ungetch(char_value) == EOF) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 346 | return PyErr_SetFromErrno(PyExc_IOError); |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 347 | Py_RETURN_NONE; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 350 | /*[clinic input] |
| 351 | msvcrt.ungetwch |
| 352 | |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 353 | unicode_char: int(accept={str}) |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 354 | / |
| 355 | |
| 356 | Wide char variant of ungetch(), accepting a Unicode value. |
| 357 | [clinic start generated code]*/ |
| 358 | |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 359 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 360 | msvcrt_ungetwch_impl(PyObject *module, int unicode_char) |
| 361 | /*[clinic end generated code: output=e63af05438b8ba3d input=83ec0492be04d564]*/ |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 362 | { |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 363 | if (_ungetwch(unicode_char) == WEOF) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 364 | return PyErr_SetFromErrno(PyExc_IOError); |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 365 | Py_RETURN_NONE; |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 366 | } |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 367 | |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 368 | #ifdef _DEBUG |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 369 | /*[clinic input] |
| 370 | msvcrt.CrtSetReportFile -> long |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 371 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 372 | type: int |
| 373 | file: int |
| 374 | / |
| 375 | |
| 376 | Wrapper around _CrtSetReportFile. |
| 377 | |
| 378 | Only available on Debug builds. |
| 379 | [clinic start generated code]*/ |
| 380 | |
| 381 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 382 | msvcrt_CrtSetReportFile_impl(PyObject *module, int type, int file) |
| 383 | /*[clinic end generated code: output=df291c7fe032eb68 input=bb8f721a604fcc45]*/ |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 384 | { |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 385 | return (long)_CrtSetReportFile(type, (_HFILE)file); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 388 | /*[clinic input] |
| 389 | msvcrt.CrtSetReportMode -> long |
| 390 | |
| 391 | type: int |
| 392 | mode: int |
| 393 | / |
| 394 | |
| 395 | Wrapper around _CrtSetReportMode. |
| 396 | |
| 397 | Only available on Debug builds. |
| 398 | [clinic start generated code]*/ |
| 399 | |
| 400 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 401 | msvcrt_CrtSetReportMode_impl(PyObject *module, int type, int mode) |
| 402 | /*[clinic end generated code: output=b2863761523de317 input=9319d29b4319426b]*/ |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 403 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 404 | int 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 | res = _CrtSetReportMode(type, mode); |
| 407 | if (res == -1) |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 408 | PyErr_SetFromErrno(PyExc_IOError); |
| 409 | return res; |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 412 | /*[clinic input] |
| 413 | msvcrt.set_error_mode -> long |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 414 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 415 | mode: int |
| 416 | / |
| 417 | |
| 418 | Wrapper around _set_error_mode. |
| 419 | |
| 420 | Only available on Debug builds. |
| 421 | [clinic start generated code]*/ |
| 422 | |
| 423 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 424 | msvcrt_set_error_mode_impl(PyObject *module, int mode) |
| 425 | /*[clinic end generated code: output=ac4a09040d8ac4e3 input=046fca59c0f20872]*/ |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 426 | { |
| 427 | return _set_error_mode(mode); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 428 | } |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 429 | #endif /* _DEBUG */ |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 430 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 431 | /*[clinic input] |
| 432 | msvcrt.SetErrorMode |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 433 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 434 | mode: unsigned_int(bitwise=True) |
| 435 | / |
| 436 | |
| 437 | Wrapper around SetErrorMode. |
| 438 | [clinic start generated code]*/ |
| 439 | |
| 440 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 441 | msvcrt_SetErrorMode_impl(PyObject *module, unsigned int mode) |
| 442 | /*[clinic end generated code: output=01d529293f00da8f input=d8b167258d32d907]*/ |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 443 | { |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 444 | unsigned int res; |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 445 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 446 | res = SetErrorMode(mode); |
| 447 | return PyLong_FromUnsignedLong(res); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 450 | /*[clinic input] |
| 451 | [clinic start generated code]*/ |
| 452 | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=da39a3ee5e6b4b0d]*/ |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 453 | |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 454 | /* List of functions exported by this module */ |
| 455 | static struct PyMethodDef msvcrt_functions[] = { |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 456 | MSVCRT_HEAPMIN_METHODDEF |
| 457 | MSVCRT_LOCKING_METHODDEF |
| 458 | MSVCRT_SETMODE_METHODDEF |
| 459 | MSVCRT_OPEN_OSFHANDLE_METHODDEF |
| 460 | MSVCRT_GET_OSFHANDLE_METHODDEF |
| 461 | MSVCRT_KBHIT_METHODDEF |
| 462 | MSVCRT_GETCH_METHODDEF |
| 463 | MSVCRT_GETCHE_METHODDEF |
| 464 | MSVCRT_PUTCH_METHODDEF |
| 465 | MSVCRT_UNGETCH_METHODDEF |
| 466 | MSVCRT_SETERRORMODE_METHODDEF |
| 467 | MSVCRT_CRTSETREPORTFILE_METHODDEF |
| 468 | MSVCRT_CRTSETREPORTMODE_METHODDEF |
| 469 | MSVCRT_SET_ERROR_MODE_METHODDEF |
| 470 | MSVCRT_GETWCH_METHODDEF |
| 471 | MSVCRT_GETWCHE_METHODDEF |
| 472 | MSVCRT_PUTWCH_METHODDEF |
| 473 | MSVCRT_UNGETWCH_METHODDEF |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 474 | {NULL, NULL} |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 475 | }; |
| 476 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 477 | |
| 478 | static struct PyModuleDef msvcrtmodule = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 479 | PyModuleDef_HEAD_INIT, |
| 480 | "msvcrt", |
| 481 | NULL, |
| 482 | -1, |
| 483 | msvcrt_functions, |
| 484 | NULL, |
| 485 | NULL, |
| 486 | NULL, |
| 487 | NULL |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 488 | }; |
| 489 | |
Zachary Ware | 4552089 | 2015-05-13 01:22:32 -0500 | [diff] [blame] | 490 | static void |
| 491 | insertint(PyObject *d, char *name, int value) |
| 492 | { |
| 493 | PyObject *v = PyLong_FromLong((long) value); |
| 494 | if (v == NULL) { |
| 495 | /* Don't bother reporting this error */ |
| 496 | PyErr_Clear(); |
| 497 | } |
| 498 | else { |
| 499 | PyDict_SetItemString(d, name, v); |
| 500 | Py_DECREF(v); |
| 501 | } |
| 502 | } |
| 503 | |
Thomas Heller | a18331d | 2004-07-28 20:02:52 +0000 | [diff] [blame] | 504 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 505 | PyInit_msvcrt(void) |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 506 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 507 | int st; |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 508 | PyObject *d, *version; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 509 | PyObject *m = PyModule_Create(&msvcrtmodule); |
| 510 | if (m == NULL) |
| 511 | return NULL; |
| 512 | d = PyModule_GetDict(m); |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 513 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 514 | /* constants for the locking() function's mode argument */ |
| 515 | insertint(d, "LK_LOCK", _LK_LOCK); |
| 516 | insertint(d, "LK_NBLCK", _LK_NBLCK); |
| 517 | insertint(d, "LK_NBRLCK", _LK_NBRLCK); |
| 518 | insertint(d, "LK_RLCK", _LK_RLCK); |
| 519 | insertint(d, "LK_UNLCK", _LK_UNLCK); |
| 520 | insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS); |
| 521 | insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT); |
| 522 | insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX); |
| 523 | insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 524 | #ifdef _DEBUG |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 525 | insertint(d, "CRT_WARN", _CRT_WARN); |
| 526 | insertint(d, "CRT_ERROR", _CRT_ERROR); |
| 527 | insertint(d, "CRT_ASSERT", _CRT_ASSERT); |
| 528 | insertint(d, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG); |
| 529 | insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE); |
| 530 | insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW); |
| 531 | insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE); |
| 532 | insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR); |
| 533 | insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT); |
| 534 | insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 535 | #endif |
Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 536 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 537 | /* constants for the crt versions */ |
Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 538 | #ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 539 | st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN", |
| 540 | _VC_ASSEMBLY_PUBLICKEYTOKEN); |
| 541 | if (st < 0) return NULL; |
Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 542 | #endif |
| 543 | #ifdef _CRT_ASSEMBLY_VERSION |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 544 | st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION", |
| 545 | _CRT_ASSEMBLY_VERSION); |
| 546 | if (st < 0) return NULL; |
Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 547 | #endif |
| 548 | #ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 549 | st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX", |
| 550 | __LIBRARIES_ASSEMBLY_NAME_PREFIX); |
| 551 | if (st < 0) return NULL; |
Benjamin Peterson | 4469d0c | 2008-11-30 22:46:23 +0000 | [diff] [blame] | 552 | #endif |
| 553 | |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 554 | /* constants for the 2010 crt versions */ |
| 555 | #if defined(_VC_CRT_MAJOR_VERSION) && defined (_VC_CRT_MINOR_VERSION) && defined(_VC_CRT_BUILD_VERSION) && defined(_VC_CRT_RBUILD_VERSION) |
| 556 | version = PyUnicode_FromFormat("%d.%d.%d.%d", _VC_CRT_MAJOR_VERSION, |
| 557 | _VC_CRT_MINOR_VERSION, |
| 558 | _VC_CRT_BUILD_VERSION, |
| 559 | _VC_CRT_RBUILD_VERSION); |
| 560 | st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version); |
| 561 | if (st < 0) return NULL; |
| 562 | #endif |
Victor Stinner | ba45295 | 2015-09-21 22:40:28 +0200 | [diff] [blame] | 563 | /* make compiler warning quiet if st is unused */ |
| 564 | (void)st; |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 565 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 566 | return m; |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 567 | } |