Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 1 | /********************************************************* |
| 2 | |
| 3 | msvcrtmodule.c |
| 4 | |
| 5 | A Python interface to the Microsoft Visual C Runtime |
| 6 | Library, providing access to those non-portable, but |
| 7 | still useful routines. |
| 8 | |
| 9 | Only ever compiled with an MS compiler, so no attempt |
| 10 | has been made to avoid MS language extensions, etc... |
| 11 | |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 12 | This may only work on NT or 95... |
| 13 | |
| 14 | Author: Mark Hammond and Guido van Rossum. |
| 15 | Maintenance: Guido van Rossum. |
| 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 | |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 27 | // Force the malloc heap to clean itself up, and free unused blocks |
| 28 | // back to the OS. (According to the docs, only works on NT.) |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 29 | static PyObject * |
| 30 | msvcrt_heapmin(PyObject *self, PyObject *args) |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 31 | { |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 32 | if (!PyArg_ParseTuple(args, ":heapmin")) |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 33 | return NULL; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 34 | |
| 35 | if (_heapmin() != 0) |
| 36 | return PyErr_SetFromErrno(PyExc_IOError); |
| 37 | |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 38 | Py_INCREF(Py_None); |
| 39 | return Py_None; |
| 40 | } |
| 41 | |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 42 | // Perform locking operations on a C runtime file descriptor. |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 43 | static PyObject * |
| 44 | msvcrt_locking(PyObject *self, PyObject *args) |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 45 | { |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 46 | int fd; |
| 47 | int mode; |
| 48 | long nbytes; |
Guido van Rossum | e4e021b | 1998-05-29 01:27:07 +0000 | [diff] [blame] | 49 | int err; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 50 | |
| 51 | if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes)) |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 52 | return NULL; |
| 53 | |
Guido van Rossum | e4e021b | 1998-05-29 01:27:07 +0000 | [diff] [blame] | 54 | Py_BEGIN_ALLOW_THREADS |
| 55 | err = _locking(fd, mode, nbytes); |
| 56 | Py_END_ALLOW_THREADS |
| 57 | if (err != 0) |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 58 | return PyErr_SetFromErrno(PyExc_IOError); |
| 59 | |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 60 | Py_INCREF(Py_None); |
| 61 | return Py_None; |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 62 | } |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 63 | |
| 64 | // Set the file translation mode for a C runtime file descriptor. |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 65 | static PyObject * |
| 66 | msvcrt_setmode(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 67 | { |
| 68 | int fd; |
| 69 | int flags; |
| 70 | if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags)) |
| 71 | return NULL; |
| 72 | |
| 73 | flags = _setmode(fd, flags); |
| 74 | if (flags == -1) |
| 75 | return PyErr_SetFromErrno(PyExc_IOError); |
| 76 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 77 | return PyLong_FromLong(flags); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // Convert an OS file handle to a C runtime file descriptor. |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 81 | static PyObject * |
| 82 | msvcrt_open_osfhandle(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 83 | { |
| 84 | long handle; |
| 85 | int flags; |
| 86 | int fd; |
| 87 | |
| 88 | if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags)) |
Guido van Rossum | e4e021b | 1998-05-29 01:27:07 +0000 | [diff] [blame] | 89 | return NULL; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 90 | |
| 91 | fd = _open_osfhandle(handle, flags); |
| 92 | if (fd == -1) |
| 93 | return PyErr_SetFromErrno(PyExc_IOError); |
| 94 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 95 | return PyLong_FromLong(fd); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | // Convert a C runtime file descriptor to an OS file handle. |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 99 | static PyObject * |
| 100 | msvcrt_get_osfhandle(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 101 | { |
| 102 | int fd; |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 103 | Py_intptr_t handle; |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 104 | |
| 105 | if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) |
| 106 | return NULL; |
| 107 | |
| 108 | handle = _get_osfhandle(fd); |
| 109 | if (handle == -1) |
| 110 | return PyErr_SetFromErrno(PyExc_IOError); |
| 111 | |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 112 | /* technically 'handle' is not a pointer, but a integer as |
| 113 | large as a pointer, Python's *VoidPtr interface is the |
| 114 | most appropriate here */ |
| 115 | return PyLong_FromVoidPtr((void*)handle); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* Console I/O */ |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 119 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 120 | static PyObject * |
| 121 | msvcrt_kbhit(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 122 | { |
| 123 | int ok; |
| 124 | |
| 125 | if (!PyArg_ParseTuple(args, ":kbhit")) |
| 126 | return NULL; |
| 127 | |
| 128 | ok = _kbhit(); |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 129 | return PyLong_FromLong(ok); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 132 | static PyObject * |
| 133 | msvcrt_getch(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 134 | { |
| 135 | int ch; |
| 136 | char s[1]; |
| 137 | |
| 138 | if (!PyArg_ParseTuple(args, ":getch")) |
| 139 | return NULL; |
| 140 | |
Guido van Rossum | e4e021b | 1998-05-29 01:27:07 +0000 | [diff] [blame] | 141 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 142 | ch = _getch(); |
Guido van Rossum | e4e021b | 1998-05-29 01:27:07 +0000 | [diff] [blame] | 143 | Py_END_ALLOW_THREADS |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 144 | s[0] = ch; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 145 | return PyBytes_FromStringAndSize(s, 1); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame^] | 148 | #ifdef _WCONIO_DEFINED |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 149 | static PyObject * |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 150 | msvcrt_getwch(PyObject *self, PyObject *args) |
| 151 | { |
| 152 | Py_UNICODE ch; |
| 153 | Py_UNICODE u[1]; |
| 154 | |
| 155 | if (!PyArg_ParseTuple(args, ":getwch")) |
| 156 | return NULL; |
| 157 | |
| 158 | Py_BEGIN_ALLOW_THREADS |
| 159 | ch = _getwch(); |
| 160 | Py_END_ALLOW_THREADS |
| 161 | u[0] = ch; |
| 162 | return PyUnicode_FromUnicode(u, 1); |
| 163 | } |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 164 | #endif |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 165 | |
| 166 | static PyObject * |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 167 | msvcrt_getche(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 168 | { |
| 169 | int ch; |
| 170 | char s[1]; |
| 171 | |
| 172 | if (!PyArg_ParseTuple(args, ":getche")) |
| 173 | return NULL; |
| 174 | |
Guido van Rossum | e4e021b | 1998-05-29 01:27:07 +0000 | [diff] [blame] | 175 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 176 | ch = _getche(); |
Guido van Rossum | e4e021b | 1998-05-29 01:27:07 +0000 | [diff] [blame] | 177 | Py_END_ALLOW_THREADS |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 178 | s[0] = ch; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 179 | return PyBytes_FromStringAndSize(s, 1); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame^] | 182 | #ifdef _WCONIO_DEFINED |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 183 | static PyObject * |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 184 | msvcrt_getwche(PyObject *self, PyObject *args) |
| 185 | { |
| 186 | Py_UNICODE ch; |
| 187 | Py_UNICODE s[1]; |
| 188 | |
| 189 | if (!PyArg_ParseTuple(args, ":getwche")) |
| 190 | return NULL; |
| 191 | |
| 192 | Py_BEGIN_ALLOW_THREADS |
| 193 | ch = _getwche(); |
| 194 | Py_END_ALLOW_THREADS |
| 195 | s[0] = ch; |
| 196 | return PyUnicode_FromUnicode(s, 1); |
| 197 | } |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 198 | #endif |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 199 | |
| 200 | static PyObject * |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 201 | msvcrt_putch(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 202 | { |
| 203 | char ch; |
| 204 | |
| 205 | if (!PyArg_ParseTuple(args, "c:putch", &ch)) |
| 206 | return NULL; |
| 207 | |
| 208 | _putch(ch); |
| 209 | Py_INCREF(Py_None); |
| 210 | return Py_None; |
| 211 | } |
| 212 | |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame^] | 213 | #ifdef _WCONIO_DEFINED |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 214 | static PyObject * |
| 215 | msvcrt_putwch(PyObject *self, PyObject *args) |
| 216 | { |
| 217 | Py_UNICODE *ch; |
| 218 | int size; |
| 219 | |
| 220 | if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size)) |
| 221 | return NULL; |
| 222 | |
| 223 | if (size == 0) { |
| 224 | PyErr_SetString(PyExc_ValueError, |
| 225 | "Expected unicode string of length 1"); |
| 226 | return NULL; |
| 227 | } |
| 228 | _putwch(*ch); |
| 229 | Py_RETURN_NONE; |
| 230 | |
| 231 | } |
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 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 234 | static PyObject * |
| 235 | msvcrt_ungetch(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 236 | { |
| 237 | char ch; |
| 238 | |
| 239 | if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) |
| 240 | return NULL; |
| 241 | |
Guido van Rossum | 6543e88 | 1999-02-16 19:40:02 +0000 | [diff] [blame] | 242 | if (_ungetch(ch) == EOF) |
| 243 | return PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 244 | Py_INCREF(Py_None); |
| 245 | return Py_None; |
| 246 | } |
| 247 | |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame^] | 248 | #ifdef _WCONIO_DEFINED |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 249 | static PyObject * |
| 250 | msvcrt_ungetwch(PyObject *self, PyObject *args) |
| 251 | { |
| 252 | Py_UNICODE ch; |
| 253 | |
| 254 | if (!PyArg_ParseTuple(args, "u:ungetwch", &ch)) |
| 255 | return NULL; |
| 256 | |
| 257 | if (_ungetch(ch) == EOF) |
| 258 | return PyErr_SetFromErrno(PyExc_IOError); |
| 259 | Py_INCREF(Py_None); |
| 260 | return Py_None; |
| 261 | } |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 262 | #endif |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 263 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 264 | static void |
| 265 | insertint(PyObject *d, char *name, int value) |
| 266 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 267 | PyObject *v = PyLong_FromLong((long) value); |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 268 | if (v == NULL) { |
| 269 | /* Don't bother reporting this error */ |
| 270 | PyErr_Clear(); |
| 271 | } |
| 272 | else { |
| 273 | PyDict_SetItemString(d, name, v); |
| 274 | Py_DECREF(v); |
| 275 | } |
| 276 | } |
| 277 | |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 278 | #ifdef _DEBUG |
| 279 | |
| 280 | static PyObject* |
| 281 | msvcrt_setreportfile(PyObject *self, PyObject *args) |
| 282 | { |
| 283 | int type, file; |
| 284 | _HFILE res; |
| 285 | |
| 286 | if (!PyArg_ParseTuple(args, "ii", &type, &file)) |
| 287 | return NULL; |
| 288 | res = _CrtSetReportFile(type, (_HFILE)file); |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 289 | return PyLong_FromLong((long)res); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 290 | Py_INCREF(Py_None); |
| 291 | return Py_None; |
| 292 | } |
| 293 | |
| 294 | static PyObject* |
| 295 | msvcrt_setreportmode(PyObject *self, PyObject *args) |
| 296 | { |
| 297 | int type, mode; |
| 298 | int res; |
| 299 | |
| 300 | if (!PyArg_ParseTuple(args, "ii", &type, &mode)) |
| 301 | return NULL; |
| 302 | res = _CrtSetReportMode(type, mode); |
| 303 | if (res == -1) |
| 304 | return PyErr_SetFromErrno(PyExc_IOError); |
| 305 | return PyLong_FromLong(res); |
| 306 | } |
| 307 | |
| 308 | static PyObject* |
| 309 | msvcrt_seterrormode(PyObject *self, PyObject *args) |
| 310 | { |
| 311 | int mode, res; |
| 312 | |
| 313 | if (!PyArg_ParseTuple(args, "i", &mode)) |
| 314 | return NULL; |
| 315 | res = _set_error_mode(mode); |
| 316 | return PyLong_FromLong(res); |
| 317 | } |
| 318 | |
| 319 | #endif |
| 320 | |
| 321 | static PyObject* |
| 322 | seterrormode(PyObject *self, PyObject *args) |
| 323 | { |
| 324 | unsigned int mode, res; |
| 325 | |
| 326 | if (!PyArg_ParseTuple(args, "I", &mode)) |
| 327 | return NULL; |
| 328 | res = SetErrorMode(mode); |
| 329 | return PyLong_FromUnsignedLong(res); |
| 330 | } |
| 331 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 332 | |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 333 | /* List of functions exported by this module */ |
| 334 | static struct PyMethodDef msvcrt_functions[] = { |
Neal Norwitz | 031829d | 2002-03-31 14:37:44 +0000 | [diff] [blame] | 335 | {"heapmin", msvcrt_heapmin, METH_VARARGS}, |
| 336 | {"locking", msvcrt_locking, METH_VARARGS}, |
| 337 | {"setmode", msvcrt_setmode, METH_VARARGS}, |
| 338 | {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS}, |
| 339 | {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS}, |
| 340 | {"kbhit", msvcrt_kbhit, METH_VARARGS}, |
| 341 | {"getch", msvcrt_getch, METH_VARARGS}, |
| 342 | {"getche", msvcrt_getche, METH_VARARGS}, |
| 343 | {"putch", msvcrt_putch, METH_VARARGS}, |
| 344 | {"ungetch", msvcrt_ungetch, METH_VARARGS}, |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 345 | {"SetErrorMode", seterrormode, METH_VARARGS}, |
| 346 | #ifdef _DEBUG |
| 347 | {"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS}, |
| 348 | {"CrtSetReportMode", msvcrt_setreportmode, METH_VARARGS}, |
| 349 | {"set_error_mode", msvcrt_seterrormode, METH_VARARGS}, |
| 350 | #endif |
Amaury Forgeot d'Arc | 3d17a5c | 2008-06-13 01:09:34 +0000 | [diff] [blame^] | 351 | #ifdef _WCONIO_DEFINED |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 352 | {"getwch", msvcrt_getwch, METH_VARARGS}, |
| 353 | {"getwche", msvcrt_getwche, METH_VARARGS}, |
| 354 | {"putwch", msvcrt_putwch, METH_VARARGS}, |
| 355 | {"ungetwch", msvcrt_ungetwch, METH_VARARGS}, |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 356 | #endif |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 357 | {NULL, NULL} |
| 358 | }; |
| 359 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 360 | |
| 361 | static struct PyModuleDef msvcrtmodule = { |
| 362 | PyModuleDef_HEAD_INIT, |
| 363 | "msvcrt", |
| 364 | NULL, |
| 365 | -1, |
| 366 | msvcrt_functions, |
| 367 | NULL, |
| 368 | NULL, |
| 369 | NULL, |
| 370 | NULL |
| 371 | }; |
| 372 | |
Thomas Heller | a18331d | 2004-07-28 20:02:52 +0000 | [diff] [blame] | 373 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 374 | PyInit_msvcrt(void) |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 375 | { |
Tim Peters | 2188bf0 | 2006-01-19 15:21:30 +0000 | [diff] [blame] | 376 | PyObject *d; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 377 | PyObject *m = PyModule_Create(&msvcrtmodule); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 378 | if (m == NULL) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 379 | return NULL; |
Tim Peters | 2188bf0 | 2006-01-19 15:21:30 +0000 | [diff] [blame] | 380 | d = PyModule_GetDict(m); |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 381 | |
| 382 | /* constants for the locking() function's mode argument */ |
| 383 | insertint(d, "LK_LOCK", _LK_LOCK); |
| 384 | insertint(d, "LK_NBLCK", _LK_NBLCK); |
| 385 | insertint(d, "LK_NBRLCK", _LK_NBRLCK); |
| 386 | insertint(d, "LK_RLCK", _LK_RLCK); |
| 387 | insertint(d, "LK_UNLCK", _LK_UNLCK); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 388 | insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS); |
| 389 | insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT); |
| 390 | insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX); |
| 391 | insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX); |
| 392 | #ifdef _DEBUG |
| 393 | insertint(d, "CRT_WARN", _CRT_WARN); |
| 394 | insertint(d, "CRT_ERROR", _CRT_ERROR); |
| 395 | insertint(d, "CRT_ASSERT", _CRT_ASSERT); |
| 396 | insertint(d, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG); |
| 397 | insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE); |
| 398 | insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW); |
| 399 | insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE); |
| 400 | insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR); |
| 401 | insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT); |
| 402 | insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE); |
| 403 | #endif |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 404 | return m; |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 405 | } |