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