| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | /*********************************************************
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	msvcrtmodule.c | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	A Python interface to the Microsoft Visual C Runtime | 
					
						
							|  |  |  | 	Library, providing access to those non-portable, but | 
					
						
							|  |  |  | 	still useful routines. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Only ever compiled with an MS compiler, so no attempt | 
					
						
							|  |  |  | 	has been made to avoid MS language extensions, etc... | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	This may only work on NT or 95... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Author: Mark Hammond and Guido van Rossum. | 
					
						
							|  |  |  | 	Maintenance: Guido van Rossum. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | ***********************************************************/ | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | #include "Python.h"
 | 
					
						
							|  |  |  | #include "malloc.h"
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | #include <io.h>
 | 
					
						
							|  |  |  | #include <conio.h>
 | 
					
						
							|  |  |  | #include <sys/locking.h>
 | 
					
						
							| 
									
										
										
										
											2007-08-31 07:58:36 +00:00
										 |  |  | #include <crtdbg.h>
 | 
					
						
							|  |  |  | #include <windows.h>
 | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Force the malloc heap to clean itself up, and free unused blocks
 | 
					
						
							|  |  |  | // back to the OS.  (According to the docs, only works on NT.)
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_heapmin(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, ":heapmin")) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (_heapmin() != 0) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 		return PyErr_SetFromErrno(PyExc_IOError); | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | // Perform locking operations on a C runtime file descriptor.
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_locking(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	int fd; | 
					
						
							|  |  |  | 	int mode; | 
					
						
							|  |  |  | 	long nbytes; | 
					
						
							| 
									
										
										
										
											1998-05-29 01:27:07 +00:00
										 |  |  | 	int err; | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes)) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-05-29 01:27:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							|  |  |  | 	err = _locking(fd, mode, nbytes); | 
					
						
							|  |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							|  |  |  | 	if (err != 0) | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 		return PyErr_SetFromErrno(PyExc_IOError); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | // Set the file translation mode for a C runtime file descriptor.
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_setmode(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int fd; | 
					
						
							|  |  |  | 	int flags; | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	flags = _setmode(fd, flags); | 
					
						
							|  |  |  | 	if (flags == -1) | 
					
						
							|  |  |  | 		return PyErr_SetFromErrno(PyExc_IOError); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-02 14:31:20 +00:00
										 |  |  | 	return PyLong_FromLong(flags); | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Convert an OS file handle to a C runtime file descriptor.
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_open_osfhandle(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	long handle; | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 	int flags; | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	int fd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags)) | 
					
						
							| 
									
										
										
										
											1998-05-29 01:27:07 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	fd = _open_osfhandle(handle, flags); | 
					
						
							|  |  |  | 	if (fd == -1) | 
					
						
							|  |  |  | 		return PyErr_SetFromErrno(PyExc_IOError); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-02 14:31:20 +00:00
										 |  |  | 	return PyLong_FromLong(fd); | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Convert a C runtime file descriptor to an OS file handle.
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_get_osfhandle(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int fd; | 
					
						
							| 
									
										
										
										
											2001-08-29 21:37:10 +00:00
										 |  |  | 	Py_intptr_t handle; | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	handle = _get_osfhandle(fd); | 
					
						
							|  |  |  | 	if (handle == -1) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 		return PyErr_SetFromErrno(PyExc_IOError); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-30 17:48:51 +00:00
										 |  |  | 	/* technically 'handle' is not a pointer, but a integer as
 | 
					
						
							|  |  |  | 	   large as a pointer, Python's *VoidPtr interface is the | 
					
						
							|  |  |  | 	   most appropriate here */ | 
					
						
							|  |  |  | 	return PyLong_FromVoidPtr((void*)handle); | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Console I/O */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_kbhit(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ok; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, ":kbhit")) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ok = _kbhit(); | 
					
						
							| 
									
										
										
										
											2007-12-02 14:31:20 +00:00
										 |  |  | 	return PyLong_FromLong(ok); | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_getch(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ch; | 
					
						
							|  |  |  | 	char s[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, ":getch")) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-05-29 01:27:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	ch = _getch(); | 
					
						
							| 
									
										
										
										
											1998-05-29 01:27:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	s[0] = ch; | 
					
						
							| 
									
										
										
										
											2008-05-26 13:28:38 +00:00
										 |  |  | 	return PyBytes_FromStringAndSize(s, 1); | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-13 01:09:34 +00:00
										 |  |  | #ifdef _WCONIO_DEFINED
 | 
					
						
							| 
									
										
										
										
											2007-12-10 16:18:49 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_getwch(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Py_UNICODE ch; | 
					
						
							|  |  |  | 	Py_UNICODE u[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, ":getwch")) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							|  |  |  | 	ch = _getwch(); | 
					
						
							|  |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							|  |  |  | 	u[0] = ch; | 
					
						
							|  |  |  | 	return PyUnicode_FromUnicode(u, 1); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-01-04 13:33:00 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-12-10 16:18:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_getche(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ch; | 
					
						
							|  |  |  | 	char s[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, ":getche")) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-05-29 01:27:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	ch = _getche(); | 
					
						
							| 
									
										
										
										
											1998-05-29 01:27:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	s[0] = ch; | 
					
						
							| 
									
										
										
										
											2008-05-26 13:28:38 +00:00
										 |  |  | 	return PyBytes_FromStringAndSize(s, 1); | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-13 01:09:34 +00:00
										 |  |  | #ifdef _WCONIO_DEFINED
 | 
					
						
							| 
									
										
										
										
											2007-12-10 16:18:49 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_getwche(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Py_UNICODE ch; | 
					
						
							|  |  |  | 	Py_UNICODE s[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, ":getwche")) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							|  |  |  | 	ch = _getwche(); | 
					
						
							|  |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							|  |  |  | 	s[0] = ch; | 
					
						
							|  |  |  | 	return PyUnicode_FromUnicode(s, 1); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-01-04 13:33:00 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-12-10 16:18:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_putch(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char ch; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "c:putch", &ch)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_putch(ch); | 
					
						
							|  |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-13 01:09:34 +00:00
										 |  |  | #ifdef _WCONIO_DEFINED
 | 
					
						
							| 
									
										
										
										
											2007-12-10 16:18:49 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_putwch(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Py_UNICODE *ch; | 
					
						
							|  |  |  | 	int size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (size == 0) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 			"Expected unicode string of length 1"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	_putwch(*ch); | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-01-04 13:33:00 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-12-10 16:18:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_ungetch(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char ch; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-16 19:40:02 +00:00
										 |  |  | 	if (_ungetch(ch) == EOF) | 
					
						
							|  |  |  | 		return PyErr_SetFromErrno(PyExc_IOError); | 
					
						
							| 
									
										
										
										
											1997-08-13 19:57:53 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-13 01:09:34 +00:00
										 |  |  | #ifdef _WCONIO_DEFINED
 | 
					
						
							| 
									
										
										
										
											2007-12-10 16:18:49 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | msvcrt_ungetwch(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Py_UNICODE ch; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "u:ungetwch", &ch)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (_ungetch(ch) == EOF) | 
					
						
							|  |  |  | 		return PyErr_SetFromErrno(PyExc_IOError); | 
					
						
							|  |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-01-04 13:33:00 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | insertint(PyObject *d, char *name, int value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-12-02 14:31:20 +00:00
										 |  |  | 	PyObject *v = PyLong_FromLong((long) value); | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | 	if (v == NULL) { | 
					
						
							|  |  |  | 		/* Don't bother reporting this error */ | 
					
						
							|  |  |  | 		PyErr_Clear(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyDict_SetItemString(d, name, v); | 
					
						
							|  |  |  | 		Py_DECREF(v); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-31 07:58:36 +00:00
										 |  |  | #ifdef _DEBUG
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject* | 
					
						
							|  |  |  | msvcrt_setreportfile(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int type, file; | 
					
						
							|  |  |  | 	_HFILE res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "ii", &type, &file)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	res = _CrtSetReportFile(type, (_HFILE)file); | 
					
						
							| 
									
										
										
										
											2007-12-02 14:31:20 +00:00
										 |  |  | 	return PyLong_FromLong((long)res); | 
					
						
							| 
									
										
										
										
											2007-08-31 07:58:36 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject* | 
					
						
							|  |  |  | msvcrt_setreportmode(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int type, mode; | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "ii", &type, &mode)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	res = _CrtSetReportMode(type, mode); | 
					
						
							|  |  |  | 	if (res == -1) | 
					
						
							|  |  |  | 	    return PyErr_SetFromErrno(PyExc_IOError); | 
					
						
							|  |  |  | 	return PyLong_FromLong(res); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject* | 
					
						
							|  |  |  | msvcrt_seterrormode(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int mode, res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "i", &mode)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	res = _set_error_mode(mode); | 
					
						
							|  |  |  | 	return PyLong_FromLong(res); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject* | 
					
						
							|  |  |  | seterrormode(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned int mode, res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "I", &mode)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	res = SetErrorMode(mode); | 
					
						
							|  |  |  | 	return PyLong_FromUnsignedLong(res); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | /* List of functions exported by this module */ | 
					
						
							|  |  |  | static struct PyMethodDef msvcrt_functions[] = { | 
					
						
							| 
									
										
										
										
											2002-03-31 14:37:44 +00:00
										 |  |  | 	{"heapmin",		msvcrt_heapmin, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"locking",             msvcrt_locking, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"setmode",		msvcrt_setmode, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"open_osfhandle",	msvcrt_open_osfhandle, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"get_osfhandle",	msvcrt_get_osfhandle, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"kbhit",		msvcrt_kbhit, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"getch",		msvcrt_getch, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"getche",		msvcrt_getche, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"putch",		msvcrt_putch, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"ungetch",		msvcrt_ungetch, METH_VARARGS}, | 
					
						
							| 
									
										
										
										
											2007-08-31 07:58:36 +00:00
										 |  |  | 	{"SetErrorMode",	seterrormode, METH_VARARGS}, | 
					
						
							|  |  |  | #ifdef _DEBUG
 | 
					
						
							|  |  |  | 	{"CrtSetReportFile",	msvcrt_setreportfile, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"CrtSetReportMode",	msvcrt_setreportmode, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"set_error_mode",	msvcrt_seterrormode, METH_VARARGS}, | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-06-13 01:09:34 +00:00
										 |  |  | #ifdef _WCONIO_DEFINED
 | 
					
						
							| 
									
										
										
										
											2007-12-10 16:18:49 +00:00
										 |  |  | 	{"getwch",		msvcrt_getwch, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"getwche",		msvcrt_getwche, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"putwch",		msvcrt_putwch, METH_VARARGS}, | 
					
						
							|  |  |  | 	{"ungetwch",		msvcrt_ungetwch, METH_VARARGS}, | 
					
						
							| 
									
										
										
										
											2008-01-04 13:33:00 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | 	{NULL,			NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-11 05:26:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct PyModuleDef msvcrtmodule = { | 
					
						
							|  |  |  | 	PyModuleDef_HEAD_INIT, | 
					
						
							|  |  |  | 	"msvcrt", | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | 	-1, | 
					
						
							|  |  |  | 	msvcrt_functions, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | 	NULL | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-28 20:02:52 +00:00
										 |  |  | PyMODINIT_FUNC | 
					
						
							| 
									
										
										
										
											2008-06-11 05:26:20 +00:00
										 |  |  | PyInit_msvcrt(void) | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-01-19 15:21:30 +00:00
										 |  |  | 	PyObject *d; | 
					
						
							| 
									
										
										
										
											2008-06-11 05:26:20 +00:00
										 |  |  | 	PyObject *m = PyModule_Create(&msvcrtmodule); | 
					
						
							| 
									
										
										
										
											2006-01-19 06:09:39 +00:00
										 |  |  | 	if (m == NULL) | 
					
						
							| 
									
										
										
										
											2008-06-11 05:26:20 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2006-01-19 15:21:30 +00:00
										 |  |  | 	d = PyModule_GetDict(m); | 
					
						
							| 
									
										
										
										
											2000-12-12 01:58:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* constants for the locking() function's mode argument */ | 
					
						
							|  |  |  | 	insertint(d, "LK_LOCK", _LK_LOCK); | 
					
						
							|  |  |  | 	insertint(d, "LK_NBLCK", _LK_NBLCK); | 
					
						
							|  |  |  | 	insertint(d, "LK_NBRLCK", _LK_NBRLCK); | 
					
						
							|  |  |  | 	insertint(d, "LK_RLCK", _LK_RLCK); | 
					
						
							|  |  |  | 	insertint(d, "LK_UNLCK", _LK_UNLCK); | 
					
						
							| 
									
										
										
										
											2007-08-31 07:58:36 +00:00
										 |  |  | 	insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS); | 
					
						
							|  |  |  | 	insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT); | 
					
						
							|  |  |  | 	insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX); | 
					
						
							|  |  |  | 	insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX); | 
					
						
							|  |  |  | #ifdef _DEBUG
 | 
					
						
							|  |  |  | 	insertint(d, "CRT_WARN", _CRT_WARN); | 
					
						
							|  |  |  | 	insertint(d, "CRT_ERROR", _CRT_ERROR); | 
					
						
							|  |  |  | 	insertint(d, "CRT_ASSERT", _CRT_ASSERT); | 
					
						
							|  |  |  | 	insertint(d, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG); | 
					
						
							|  |  |  | 	insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE); | 
					
						
							|  |  |  | 	insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW); | 
					
						
							|  |  |  | 	insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE); | 
					
						
							|  |  |  | 	insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR); | 
					
						
							|  |  |  | 	insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT); | 
					
						
							|  |  |  | 	insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-06-11 05:26:20 +00:00
										 |  |  | 	return m; | 
					
						
							| 
									
										
										
										
											1997-08-07 00:11:34 +00:00
										 |  |  | } |