blob: 48e739f2b768c603819dc0edfaef73031dc9b16d [file] [log] [blame]
Guido van Rossum29c1ea51997-08-07 00:11:34 +00001/*********************************************************
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 Rossum407a22d1997-08-13 19:57:53 +000012 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 Rossum29c1ea51997-08-07 00:11:34 +000017***********************************************************/
Guido van Rossum407a22d1997-08-13 19:57:53 +000018
Guido van Rossum29c1ea51997-08-07 00:11:34 +000019#include "Python.h"
20#include "malloc.h"
Tim Peters5fa0bd62000-12-12 01:58:56 +000021#include <io.h>
22#include <conio.h>
23#include <sys/locking.h>
Martin v. Löwis3dc33d12007-08-31 07:58:36 +000024#include <crtdbg.h>
25#include <windows.h>
Guido van Rossum29c1ea51997-08-07 00:11:34 +000026
Benjamin Peterson4469d0c2008-11-30 22:46:23 +000027#ifdef _MSC_VER
28#if _MSC_VER >= 1500
29#include <crtassem.h>
30#endif
31#endif
32
Guido van Rossum407a22d1997-08-13 19:57:53 +000033// Force the malloc heap to clean itself up, and free unused blocks
34// back to the OS. (According to the docs, only works on NT.)
Tim Peters5fa0bd62000-12-12 01:58:56 +000035static PyObject *
36msvcrt_heapmin(PyObject *self, PyObject *args)
Guido van Rossum29c1ea51997-08-07 00:11:34 +000037{
Guido van Rossum407a22d1997-08-13 19:57:53 +000038 if (!PyArg_ParseTuple(args, ":heapmin"))
Guido van Rossum29c1ea51997-08-07 00:11:34 +000039 return NULL;
Guido van Rossum407a22d1997-08-13 19:57:53 +000040
41 if (_heapmin() != 0)
42 return PyErr_SetFromErrno(PyExc_IOError);
43
Guido van Rossum29c1ea51997-08-07 00:11:34 +000044 Py_INCREF(Py_None);
45 return Py_None;
46}
47
Benjamin Peterson1baf4652009-12-31 03:11:23 +000048PyDoc_STRVAR(heapmin_doc,
49"heapmin() -> None\n\
50\n\
51Force the malloc() heap to clean itself up and return unused blocks\n\
52to the operating system. On failure, this raises IOError.");
53
Guido van Rossum407a22d1997-08-13 19:57:53 +000054// Perform locking operations on a C runtime file descriptor.
Tim Peters5fa0bd62000-12-12 01:58:56 +000055static PyObject *
56msvcrt_locking(PyObject *self, PyObject *args)
Guido van Rossum29c1ea51997-08-07 00:11:34 +000057{
Guido van Rossum407a22d1997-08-13 19:57:53 +000058 int fd;
59 int mode;
60 long nbytes;
Guido van Rossume4e021b1998-05-29 01:27:07 +000061 int err;
Guido van Rossum407a22d1997-08-13 19:57:53 +000062
63 if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes))
Guido van Rossum29c1ea51997-08-07 00:11:34 +000064 return NULL;
65
Guido van Rossume4e021b1998-05-29 01:27:07 +000066 Py_BEGIN_ALLOW_THREADS
67 err = _locking(fd, mode, nbytes);
68 Py_END_ALLOW_THREADS
69 if (err != 0)
Guido van Rossum29c1ea51997-08-07 00:11:34 +000070 return PyErr_SetFromErrno(PyExc_IOError);
71
Guido van Rossum407a22d1997-08-13 19:57:53 +000072 Py_INCREF(Py_None);
73 return Py_None;
Guido van Rossum29c1ea51997-08-07 00:11:34 +000074}
Guido van Rossum407a22d1997-08-13 19:57:53 +000075
Benjamin Peterson1baf4652009-12-31 03:11:23 +000076PyDoc_STRVAR(locking_doc,
77"locking(fd, mode, nbytes) -> None\n\
78\n\
79Lock part of a file based on file descriptor fd from the C runtime.\n\
80Raises IOError on failure. The locked region of the file extends from\n\
81the current file position for nbytes bytes, and may continue beyond\n\
82the end of the file. mode must be one of the LK_* constants listed\n\
83below. Multiple regions in a file may be locked at the same time, but\n\
84may not overlap. Adjacent regions are not merged; they must be unlocked\n\
85individually.");
86
Guido van Rossum407a22d1997-08-13 19:57:53 +000087// Set the file translation mode for a C runtime file descriptor.
Tim Peters5fa0bd62000-12-12 01:58:56 +000088static PyObject *
89msvcrt_setmode(PyObject *self, PyObject *args)
Guido van Rossum407a22d1997-08-13 19:57:53 +000090{
91 int fd;
92 int flags;
93 if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags))
94 return NULL;
95
96 flags = _setmode(fd, flags);
97 if (flags == -1)
98 return PyErr_SetFromErrno(PyExc_IOError);
99
Christian Heimes217cfd12007-12-02 14:31:20 +0000100 return PyLong_FromLong(flags);
Guido van Rossum407a22d1997-08-13 19:57:53 +0000101}
102
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000103PyDoc_STRVAR(setmode_doc,
104"setmode(fd, mode) -> Previous mode\n\
105\n\
106Set the line-end translation mode for the file descriptor fd. To set\n\
107it to text mode, flags should be os.O_TEXT; for binary, it should be\n\
108os.O_BINARY.");
109
Guido van Rossum407a22d1997-08-13 19:57:53 +0000110// Convert an OS file handle to a C runtime file descriptor.
Tim Peters5fa0bd62000-12-12 01:58:56 +0000111static PyObject *
112msvcrt_open_osfhandle(PyObject *self, PyObject *args)
Guido van Rossum407a22d1997-08-13 19:57:53 +0000113{
114 long handle;
115 int flags;
116 int fd;
117
118 if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags))
Guido van Rossume4e021b1998-05-29 01:27:07 +0000119 return NULL;
Guido van Rossum407a22d1997-08-13 19:57:53 +0000120
121 fd = _open_osfhandle(handle, flags);
122 if (fd == -1)
123 return PyErr_SetFromErrno(PyExc_IOError);
124
Christian Heimes217cfd12007-12-02 14:31:20 +0000125 return PyLong_FromLong(fd);
Guido van Rossum407a22d1997-08-13 19:57:53 +0000126}
127
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000128PyDoc_STRVAR(open_osfhandle_doc,
129"open_osfhandle(handle, flags) -> file descriptor\n\
130\n\
131Create a C runtime file descriptor from the file handle handle. The\n\
132flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n\
133and os.O_TEXT. The returned file descriptor may be used as a parameter\n\
134to os.fdopen() to create a file object.");
135
Guido van Rossum407a22d1997-08-13 19:57:53 +0000136// Convert a C runtime file descriptor to an OS file handle.
Tim Peters5fa0bd62000-12-12 01:58:56 +0000137static PyObject *
138msvcrt_get_osfhandle(PyObject *self, PyObject *args)
Guido van Rossum407a22d1997-08-13 19:57:53 +0000139{
140 int fd;
Tim Peters79248aa2001-08-29 21:37:10 +0000141 Py_intptr_t handle;
Guido van Rossum407a22d1997-08-13 19:57:53 +0000142
143 if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
144 return NULL;
145
146 handle = _get_osfhandle(fd);
147 if (handle == -1)
148 return PyErr_SetFromErrno(PyExc_IOError);
149
Fred Drake25e17262000-06-30 17:48:51 +0000150 /* technically 'handle' is not a pointer, but a integer as
151 large as a pointer, Python's *VoidPtr interface is the
152 most appropriate here */
153 return PyLong_FromVoidPtr((void*)handle);
Guido van Rossum407a22d1997-08-13 19:57:53 +0000154}
155
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000156PyDoc_STRVAR(get_osfhandle_doc,
157"get_osfhandle(fd) -> file handle\n\
158\n\
159Return the file handle for the file descriptor fd. Raises IOError\n\
160if fd is not recognized.");
161
Guido van Rossum407a22d1997-08-13 19:57:53 +0000162/* Console I/O */
Guido van Rossum407a22d1997-08-13 19:57:53 +0000163
Tim Peters5fa0bd62000-12-12 01:58:56 +0000164static PyObject *
165msvcrt_kbhit(PyObject *self, PyObject *args)
Guido van Rossum407a22d1997-08-13 19:57:53 +0000166{
167 int ok;
168
169 if (!PyArg_ParseTuple(args, ":kbhit"))
170 return NULL;
171
172 ok = _kbhit();
Christian Heimes217cfd12007-12-02 14:31:20 +0000173 return PyLong_FromLong(ok);
Guido van Rossum407a22d1997-08-13 19:57:53 +0000174}
175
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000176PyDoc_STRVAR(kbhit_doc,
177"kbhit() -> bool\n\
178\n\
179Return true if a keypress is waiting to be read.");
180
Tim Peters5fa0bd62000-12-12 01:58:56 +0000181static PyObject *
182msvcrt_getch(PyObject *self, PyObject *args)
Guido van Rossum407a22d1997-08-13 19:57:53 +0000183{
184 int ch;
185 char s[1];
186
187 if (!PyArg_ParseTuple(args, ":getch"))
188 return NULL;
189
Guido van Rossume4e021b1998-05-29 01:27:07 +0000190 Py_BEGIN_ALLOW_THREADS
Guido van Rossum407a22d1997-08-13 19:57:53 +0000191 ch = _getch();
Guido van Rossume4e021b1998-05-29 01:27:07 +0000192 Py_END_ALLOW_THREADS
Guido van Rossum407a22d1997-08-13 19:57:53 +0000193 s[0] = ch;
Christian Heimes72b710a2008-05-26 13:28:38 +0000194 return PyBytes_FromStringAndSize(s, 1);
Guido van Rossum407a22d1997-08-13 19:57:53 +0000195}
196
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000197PyDoc_STRVAR(getch_doc,
198"getch() -> key character\n\
199\n\
200Read a keypress and return the resulting character. Nothing is echoed to\n\
201the console. This call will block if a keypress is not already\n\
202available, but will not wait for Enter to be pressed. If the pressed key\n\
203was a special function key, this will return '\\000' or '\\xe0'; the next\n\
204call will return the keycode. The Control-C keypress cannot be read with\n\
205this function.");
206
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000207#ifdef _WCONIO_DEFINED
Tim Peters5fa0bd62000-12-12 01:58:56 +0000208static PyObject *
Christian Heimes2f1019e2007-12-10 16:18:49 +0000209msvcrt_getwch(PyObject *self, PyObject *args)
210{
211 Py_UNICODE ch;
212 Py_UNICODE u[1];
213
214 if (!PyArg_ParseTuple(args, ":getwch"))
215 return NULL;
216
217 Py_BEGIN_ALLOW_THREADS
218 ch = _getwch();
219 Py_END_ALLOW_THREADS
220 u[0] = ch;
221 return PyUnicode_FromUnicode(u, 1);
222}
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000223
224PyDoc_STRVAR(getwch_doc,
225"getwch() -> Unicode key character\n\
226\n\
227Wide char variant of getch(), returning a Unicode value.");
Christian Heimesc36625b2008-01-04 13:33:00 +0000228#endif
Christian Heimes2f1019e2007-12-10 16:18:49 +0000229
230static PyObject *
Tim Peters5fa0bd62000-12-12 01:58:56 +0000231msvcrt_getche(PyObject *self, PyObject *args)
Guido van Rossum407a22d1997-08-13 19:57:53 +0000232{
233 int ch;
234 char s[1];
235
236 if (!PyArg_ParseTuple(args, ":getche"))
237 return NULL;
238
Guido van Rossume4e021b1998-05-29 01:27:07 +0000239 Py_BEGIN_ALLOW_THREADS
Guido van Rossum407a22d1997-08-13 19:57:53 +0000240 ch = _getche();
Guido van Rossume4e021b1998-05-29 01:27:07 +0000241 Py_END_ALLOW_THREADS
Guido van Rossum407a22d1997-08-13 19:57:53 +0000242 s[0] = ch;
Christian Heimes72b710a2008-05-26 13:28:38 +0000243 return PyBytes_FromStringAndSize(s, 1);
Guido van Rossum407a22d1997-08-13 19:57:53 +0000244}
245
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000246PyDoc_STRVAR(getche_doc,
247"getche() -> key character\n\
248\n\
249Similar to getch(), but the keypress will be echoed if it represents\n\
250a printable character.");
251
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000252#ifdef _WCONIO_DEFINED
Tim Peters5fa0bd62000-12-12 01:58:56 +0000253static PyObject *
Christian Heimes2f1019e2007-12-10 16:18:49 +0000254msvcrt_getwche(PyObject *self, PyObject *args)
255{
256 Py_UNICODE ch;
257 Py_UNICODE s[1];
258
259 if (!PyArg_ParseTuple(args, ":getwche"))
260 return NULL;
261
262 Py_BEGIN_ALLOW_THREADS
263 ch = _getwche();
264 Py_END_ALLOW_THREADS
265 s[0] = ch;
266 return PyUnicode_FromUnicode(s, 1);
267}
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000268
269PyDoc_STRVAR(getwche_doc,
270"getwche() -> Unicode key character\n\
271\n\
272Wide char variant of getche(), returning a Unicode value.");
Christian Heimesc36625b2008-01-04 13:33:00 +0000273#endif
Christian Heimes2f1019e2007-12-10 16:18:49 +0000274
275static PyObject *
Tim Peters5fa0bd62000-12-12 01:58:56 +0000276msvcrt_putch(PyObject *self, PyObject *args)
Guido van Rossum407a22d1997-08-13 19:57:53 +0000277{
278 char ch;
279
280 if (!PyArg_ParseTuple(args, "c:putch", &ch))
281 return NULL;
282
283 _putch(ch);
284 Py_INCREF(Py_None);
285 return Py_None;
286}
287
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000288PyDoc_STRVAR(putch_doc,
289"putch(char) -> None\n\
290\n\
291Print the character char to the console without buffering.");
292
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000293#ifdef _WCONIO_DEFINED
Christian Heimes2f1019e2007-12-10 16:18:49 +0000294static PyObject *
295msvcrt_putwch(PyObject *self, PyObject *args)
296{
Benjamin Peterson435b0f22009-05-01 21:42:23 +0000297 int ch;
Christian Heimes2f1019e2007-12-10 16:18:49 +0000298
Benjamin Peterson435b0f22009-05-01 21:42:23 +0000299 if (!PyArg_ParseTuple(args, "C:putwch", &ch))
Christian Heimes2f1019e2007-12-10 16:18:49 +0000300 return NULL;
301
Benjamin Peterson435b0f22009-05-01 21:42:23 +0000302 _putwch(ch);
Christian Heimes2f1019e2007-12-10 16:18:49 +0000303 Py_RETURN_NONE;
304
305}
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000306
307PyDoc_STRVAR(putwch_doc,
308"putwch(unicode_char) -> None\n\
309\n\
310Wide char variant of putch(), accepting a Unicode value.");
Christian Heimesc36625b2008-01-04 13:33:00 +0000311#endif
Christian Heimes2f1019e2007-12-10 16:18:49 +0000312
Tim Peters5fa0bd62000-12-12 01:58:56 +0000313static PyObject *
314msvcrt_ungetch(PyObject *self, PyObject *args)
Guido van Rossum407a22d1997-08-13 19:57:53 +0000315{
316 char ch;
317
318 if (!PyArg_ParseTuple(args, "c:ungetch", &ch))
319 return NULL;
320
Guido van Rossum6543e881999-02-16 19:40:02 +0000321 if (_ungetch(ch) == EOF)
322 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum407a22d1997-08-13 19:57:53 +0000323 Py_INCREF(Py_None);
324 return Py_None;
325}
326
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000327PyDoc_STRVAR(ungetch_doc,
328"ungetch(char) -> None\n\
329\n\
330Cause the character char to be \"pushed back\" into the console buffer;\n\
331it will be the next character read by getch() or getche().");
332
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000333#ifdef _WCONIO_DEFINED
Christian Heimes2f1019e2007-12-10 16:18:49 +0000334static PyObject *
335msvcrt_ungetwch(PyObject *self, PyObject *args)
336{
Benjamin Peterson435b0f22009-05-01 21:42:23 +0000337 int ch;
Christian Heimes2f1019e2007-12-10 16:18:49 +0000338
Benjamin Peterson435b0f22009-05-01 21:42:23 +0000339 if (!PyArg_ParseTuple(args, "C:ungetwch", &ch))
Christian Heimes2f1019e2007-12-10 16:18:49 +0000340 return NULL;
341
Benjamin Peterson435b0f22009-05-01 21:42:23 +0000342 if (_ungetwch(ch) == WEOF)
Christian Heimes2f1019e2007-12-10 16:18:49 +0000343 return PyErr_SetFromErrno(PyExc_IOError);
344 Py_INCREF(Py_None);
345 return Py_None;
346}
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000347
348PyDoc_STRVAR(ungetwch_doc,
349"ungetwch(unicode_char) -> None\n\
350\n\
351Wide char variant of ungetch(), accepting a Unicode value.");
Christian Heimesc36625b2008-01-04 13:33:00 +0000352#endif
Guido van Rossum29c1ea51997-08-07 00:11:34 +0000353
Tim Peters5fa0bd62000-12-12 01:58:56 +0000354static void
355insertint(PyObject *d, char *name, int value)
356{
Christian Heimes217cfd12007-12-02 14:31:20 +0000357 PyObject *v = PyLong_FromLong((long) value);
Tim Peters5fa0bd62000-12-12 01:58:56 +0000358 if (v == NULL) {
359 /* Don't bother reporting this error */
360 PyErr_Clear();
361 }
362 else {
363 PyDict_SetItemString(d, name, v);
364 Py_DECREF(v);
365 }
366}
367
Martin v. Löwis3dc33d12007-08-31 07:58:36 +0000368#ifdef _DEBUG
369
370static PyObject*
371msvcrt_setreportfile(PyObject *self, PyObject *args)
372{
373 int type, file;
374 _HFILE res;
375
376 if (!PyArg_ParseTuple(args, "ii", &type, &file))
377 return NULL;
378 res = _CrtSetReportFile(type, (_HFILE)file);
Christian Heimes217cfd12007-12-02 14:31:20 +0000379 return PyLong_FromLong((long)res);
Martin v. Löwis3dc33d12007-08-31 07:58:36 +0000380 Py_INCREF(Py_None);
381 return Py_None;
382}
383
384static PyObject*
385msvcrt_setreportmode(PyObject *self, PyObject *args)
386{
387 int type, mode;
388 int res;
389
390 if (!PyArg_ParseTuple(args, "ii", &type, &mode))
391 return NULL;
392 res = _CrtSetReportMode(type, mode);
393 if (res == -1)
394 return PyErr_SetFromErrno(PyExc_IOError);
395 return PyLong_FromLong(res);
396}
397
398static PyObject*
399msvcrt_seterrormode(PyObject *self, PyObject *args)
400{
401 int mode, res;
402
403 if (!PyArg_ParseTuple(args, "i", &mode))
404 return NULL;
405 res = _set_error_mode(mode);
406 return PyLong_FromLong(res);
407}
408
409#endif
410
411static PyObject*
412seterrormode(PyObject *self, PyObject *args)
413{
414 unsigned int mode, res;
415
416 if (!PyArg_ParseTuple(args, "I", &mode))
417 return NULL;
418 res = SetErrorMode(mode);
419 return PyLong_FromUnsignedLong(res);
420}
421
Tim Peters5fa0bd62000-12-12 01:58:56 +0000422
Guido van Rossum29c1ea51997-08-07 00:11:34 +0000423/* List of functions exported by this module */
424static struct PyMethodDef msvcrt_functions[] = {
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000425 {"heapmin", msvcrt_heapmin, METH_VARARGS, heapmin_doc},
426 {"locking", msvcrt_locking, METH_VARARGS, locking_doc},
427 {"setmode", msvcrt_setmode, METH_VARARGS, setmode_doc},
428 {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS, open_osfhandle_doc},
429 {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS, get_osfhandle_doc},
430 {"kbhit", msvcrt_kbhit, METH_VARARGS, kbhit_doc},
431 {"getch", msvcrt_getch, METH_VARARGS, getch_doc},
432 {"getche", msvcrt_getche, METH_VARARGS, getche_doc},
433 {"putch", msvcrt_putch, METH_VARARGS, putch_doc},
434 {"ungetch", msvcrt_ungetch, METH_VARARGS, ungetch_doc},
Martin v. Löwis3dc33d12007-08-31 07:58:36 +0000435 {"SetErrorMode", seterrormode, METH_VARARGS},
436#ifdef _DEBUG
437 {"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS},
438 {"CrtSetReportMode", msvcrt_setreportmode, METH_VARARGS},
439 {"set_error_mode", msvcrt_seterrormode, METH_VARARGS},
440#endif
Amaury Forgeot d'Arc3d17a5c2008-06-13 01:09:34 +0000441#ifdef _WCONIO_DEFINED
Benjamin Peterson1baf4652009-12-31 03:11:23 +0000442 {"getwch", msvcrt_getwch, METH_VARARGS, getwch_doc},
443 {"getwche", msvcrt_getwche, METH_VARARGS, getwche_doc},
444 {"putwch", msvcrt_putwch, METH_VARARGS, putwch_doc},
445 {"ungetwch", msvcrt_ungetwch, METH_VARARGS, ungetwch_doc},
Christian Heimesc36625b2008-01-04 13:33:00 +0000446#endif
Guido van Rossum29c1ea51997-08-07 00:11:34 +0000447 {NULL, NULL}
448};
449
Martin v. Löwis1a214512008-06-11 05:26:20 +0000450
451static struct PyModuleDef msvcrtmodule = {
452 PyModuleDef_HEAD_INIT,
453 "msvcrt",
454 NULL,
455 -1,
456 msvcrt_functions,
457 NULL,
458 NULL,
459 NULL,
460 NULL
461};
462
Thomas Hellera18331d2004-07-28 20:02:52 +0000463PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +0000464PyInit_msvcrt(void)
Guido van Rossum29c1ea51997-08-07 00:11:34 +0000465{
Benjamin Peterson4469d0c2008-11-30 22:46:23 +0000466 int st;
Tim Peters2188bf02006-01-19 15:21:30 +0000467 PyObject *d;
Martin v. Löwis1a214512008-06-11 05:26:20 +0000468 PyObject *m = PyModule_Create(&msvcrtmodule);
Neal Norwitz1ac754f2006-01-19 06:09:39 +0000469 if (m == NULL)
Martin v. Löwis1a214512008-06-11 05:26:20 +0000470 return NULL;
Tim Peters2188bf02006-01-19 15:21:30 +0000471 d = PyModule_GetDict(m);
Tim Peters5fa0bd62000-12-12 01:58:56 +0000472
473 /* constants for the locking() function's mode argument */
474 insertint(d, "LK_LOCK", _LK_LOCK);
475 insertint(d, "LK_NBLCK", _LK_NBLCK);
476 insertint(d, "LK_NBRLCK", _LK_NBRLCK);
477 insertint(d, "LK_RLCK", _LK_RLCK);
478 insertint(d, "LK_UNLCK", _LK_UNLCK);
Martin v. Löwis3dc33d12007-08-31 07:58:36 +0000479 insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS);
480 insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT);
481 insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX);
482 insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX);
483#ifdef _DEBUG
484 insertint(d, "CRT_WARN", _CRT_WARN);
485 insertint(d, "CRT_ERROR", _CRT_ERROR);
486 insertint(d, "CRT_ASSERT", _CRT_ASSERT);
487 insertint(d, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG);
488 insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE);
489 insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW);
490 insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE);
491 insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR);
492 insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT);
493 insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE);
494#endif
Benjamin Peterson4469d0c2008-11-30 22:46:23 +0000495
496 /* constants for the crt versions */
497#ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN
498 st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN",
499 _VC_ASSEMBLY_PUBLICKEYTOKEN);
500 if (st < 0) return NULL;
501#endif
502#ifdef _CRT_ASSEMBLY_VERSION
503 st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION",
504 _CRT_ASSEMBLY_VERSION);
505 if (st < 0) return NULL;
506#endif
507#ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX
508 st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX",
509 __LIBRARIES_ASSEMBLY_NAME_PREFIX);
510 if (st < 0) return NULL;
511#endif
512
513 return m;
Guido van Rossum29c1ea51997-08-07 00:11:34 +0000514}