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; |
| 145 | return PyString_FromStringAndSize(s, 1); |
| 146 | } |
| 147 | |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 148 | #if _MSC_VER >= 1300 |
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; |
| 179 | return PyString_FromStringAndSize(s, 1); |
| 180 | } |
| 181 | |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 182 | #if _MSC_VER >= 1300 |
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 | |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 213 | |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 214 | #if _MSC_VER >= 1300 |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 215 | static PyObject * |
| 216 | msvcrt_putwch(PyObject *self, PyObject *args) |
| 217 | { |
| 218 | Py_UNICODE *ch; |
| 219 | int size; |
| 220 | |
| 221 | if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size)) |
| 222 | return NULL; |
| 223 | |
| 224 | if (size == 0) { |
| 225 | PyErr_SetString(PyExc_ValueError, |
| 226 | "Expected unicode string of length 1"); |
| 227 | return NULL; |
| 228 | } |
| 229 | _putwch(*ch); |
| 230 | Py_RETURN_NONE; |
| 231 | |
| 232 | } |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 233 | #endif |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 234 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 235 | static PyObject * |
| 236 | msvcrt_ungetch(PyObject *self, PyObject *args) |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 237 | { |
| 238 | char ch; |
| 239 | |
| 240 | if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) |
| 241 | return NULL; |
| 242 | |
Guido van Rossum | 6543e88 | 1999-02-16 19:40:02 +0000 | [diff] [blame] | 243 | if (_ungetch(ch) == EOF) |
| 244 | return PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 407a22d | 1997-08-13 19:57:53 +0000 | [diff] [blame] | 245 | Py_INCREF(Py_None); |
| 246 | return Py_None; |
| 247 | } |
| 248 | |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 249 | #if _MSC_VER >= 1300 |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 250 | static PyObject * |
| 251 | msvcrt_ungetwch(PyObject *self, PyObject *args) |
| 252 | { |
| 253 | Py_UNICODE ch; |
| 254 | |
| 255 | if (!PyArg_ParseTuple(args, "u:ungetwch", &ch)) |
| 256 | return NULL; |
| 257 | |
| 258 | if (_ungetch(ch) == EOF) |
| 259 | return PyErr_SetFromErrno(PyExc_IOError); |
| 260 | Py_INCREF(Py_None); |
| 261 | return Py_None; |
| 262 | } |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 263 | #endif |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 264 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 265 | static void |
| 266 | insertint(PyObject *d, char *name, int value) |
| 267 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 268 | PyObject *v = PyLong_FromLong((long) value); |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 269 | if (v == NULL) { |
| 270 | /* Don't bother reporting this error */ |
| 271 | PyErr_Clear(); |
| 272 | } |
| 273 | else { |
| 274 | PyDict_SetItemString(d, name, v); |
| 275 | Py_DECREF(v); |
| 276 | } |
| 277 | } |
| 278 | |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 279 | #ifdef _DEBUG |
| 280 | |
| 281 | static PyObject* |
| 282 | msvcrt_setreportfile(PyObject *self, PyObject *args) |
| 283 | { |
| 284 | int type, file; |
| 285 | _HFILE res; |
| 286 | |
| 287 | if (!PyArg_ParseTuple(args, "ii", &type, &file)) |
| 288 | return NULL; |
| 289 | res = _CrtSetReportFile(type, (_HFILE)file); |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 290 | return PyLong_FromLong((long)res); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 291 | Py_INCREF(Py_None); |
| 292 | return Py_None; |
| 293 | } |
| 294 | |
| 295 | static PyObject* |
| 296 | msvcrt_setreportmode(PyObject *self, PyObject *args) |
| 297 | { |
| 298 | int type, mode; |
| 299 | int res; |
| 300 | |
| 301 | if (!PyArg_ParseTuple(args, "ii", &type, &mode)) |
| 302 | return NULL; |
| 303 | res = _CrtSetReportMode(type, mode); |
| 304 | if (res == -1) |
| 305 | return PyErr_SetFromErrno(PyExc_IOError); |
| 306 | return PyLong_FromLong(res); |
| 307 | } |
| 308 | |
| 309 | static PyObject* |
| 310 | msvcrt_seterrormode(PyObject *self, PyObject *args) |
| 311 | { |
| 312 | int mode, res; |
| 313 | |
| 314 | if (!PyArg_ParseTuple(args, "i", &mode)) |
| 315 | return NULL; |
| 316 | res = _set_error_mode(mode); |
| 317 | return PyLong_FromLong(res); |
| 318 | } |
| 319 | |
| 320 | #endif |
| 321 | |
| 322 | static PyObject* |
| 323 | seterrormode(PyObject *self, PyObject *args) |
| 324 | { |
| 325 | unsigned int mode, res; |
| 326 | |
| 327 | if (!PyArg_ParseTuple(args, "I", &mode)) |
| 328 | return NULL; |
| 329 | res = SetErrorMode(mode); |
| 330 | return PyLong_FromUnsignedLong(res); |
| 331 | } |
| 332 | |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 333 | |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 334 | /* List of functions exported by this module */ |
| 335 | static struct PyMethodDef msvcrt_functions[] = { |
Neal Norwitz | 031829d | 2002-03-31 14:37:44 +0000 | [diff] [blame] | 336 | {"heapmin", msvcrt_heapmin, METH_VARARGS}, |
| 337 | {"locking", msvcrt_locking, METH_VARARGS}, |
| 338 | {"setmode", msvcrt_setmode, METH_VARARGS}, |
| 339 | {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS}, |
| 340 | {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS}, |
| 341 | {"kbhit", msvcrt_kbhit, METH_VARARGS}, |
| 342 | {"getch", msvcrt_getch, METH_VARARGS}, |
| 343 | {"getche", msvcrt_getche, METH_VARARGS}, |
| 344 | {"putch", msvcrt_putch, METH_VARARGS}, |
| 345 | {"ungetch", msvcrt_ungetch, METH_VARARGS}, |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 346 | {"SetErrorMode", seterrormode, METH_VARARGS}, |
| 347 | #ifdef _DEBUG |
| 348 | {"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS}, |
| 349 | {"CrtSetReportMode", msvcrt_setreportmode, METH_VARARGS}, |
| 350 | {"set_error_mode", msvcrt_seterrormode, METH_VARARGS}, |
| 351 | #endif |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 352 | #if _MSC_VER >= 1300 |
Christian Heimes | 2f1019e | 2007-12-10 16:18:49 +0000 | [diff] [blame] | 353 | {"getwch", msvcrt_getwch, METH_VARARGS}, |
| 354 | {"getwche", msvcrt_getwche, METH_VARARGS}, |
| 355 | {"putwch", msvcrt_putwch, METH_VARARGS}, |
| 356 | {"ungetwch", msvcrt_ungetwch, METH_VARARGS}, |
Christian Heimes | c36625b | 2008-01-04 13:33:00 +0000 | [diff] [blame] | 357 | #endif |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 358 | {NULL, NULL} |
| 359 | }; |
| 360 | |
Thomas Heller | a18331d | 2004-07-28 20:02:52 +0000 | [diff] [blame] | 361 | PyMODINIT_FUNC |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 362 | initmsvcrt(void) |
| 363 | { |
Tim Peters | 2188bf0 | 2006-01-19 15:21:30 +0000 | [diff] [blame] | 364 | PyObject *d; |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 365 | PyObject *m = Py_InitModule("msvcrt", msvcrt_functions); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 366 | if (m == NULL) |
| 367 | return; |
Tim Peters | 2188bf0 | 2006-01-19 15:21:30 +0000 | [diff] [blame] | 368 | d = PyModule_GetDict(m); |
Tim Peters | 5fa0bd6 | 2000-12-12 01:58:56 +0000 | [diff] [blame] | 369 | |
| 370 | /* constants for the locking() function's mode argument */ |
| 371 | insertint(d, "LK_LOCK", _LK_LOCK); |
| 372 | insertint(d, "LK_NBLCK", _LK_NBLCK); |
| 373 | insertint(d, "LK_NBRLCK", _LK_NBRLCK); |
| 374 | insertint(d, "LK_RLCK", _LK_RLCK); |
| 375 | insertint(d, "LK_UNLCK", _LK_UNLCK); |
Martin v. Löwis | 3dc33d1 | 2007-08-31 07:58:36 +0000 | [diff] [blame] | 376 | insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS); |
| 377 | insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT); |
| 378 | insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX); |
| 379 | insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX); |
| 380 | #ifdef _DEBUG |
| 381 | insertint(d, "CRT_WARN", _CRT_WARN); |
| 382 | insertint(d, "CRT_ERROR", _CRT_ERROR); |
| 383 | insertint(d, "CRT_ASSERT", _CRT_ASSERT); |
| 384 | insertint(d, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG); |
| 385 | insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE); |
| 386 | insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW); |
| 387 | insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE); |
| 388 | insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR); |
| 389 | insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT); |
| 390 | insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE); |
| 391 | #endif |
Guido van Rossum | 29c1ea5 | 1997-08-07 00:11:34 +0000 | [diff] [blame] | 392 | } |