summaryrefslogtreecommitdiff
path: root/PC/msvcrtmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-07 00:11:34 +0000
committerGuido van Rossum <guido@python.org>1997-08-07 00:11:34 +0000
commita6571c37e9062dae339077cdf8f7f5e630df8350 (patch)
treebb6e03272a26fdc183d2ea8e11db3c6a9ca860d4 /PC/msvcrtmodule.c
parent30b15b2398465524ec33c5348777a6580594677a (diff)
downloadcpython-a6571c37e9062dae339077cdf8f7f5e630df8350.tar.gz
Got the new structure working with MSVC 4.2.
main_nt.c is gone -- we can use Modules/python.c now. Added Mark Hammond's module msvcrt.c (untested). Added several new symbols.
Diffstat (limited to 'PC/msvcrtmodule.c')
-rwxr-xr-xPC/msvcrtmodule.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c
new file mode 100755
index 0000000000..dec628516a
--- /dev/null
+++ b/PC/msvcrtmodule.c
@@ -0,0 +1,95 @@
+/*********************************************************
+
+ 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...
+
+***********************************************************/
+#include "Python.h"
+#include "malloc.h"
+// Perform locking operations on a file.
+static PyObject *msvcrt_locking(PyObject *self, PyObject *args)
+{
+ int mode;
+ long nBytes;
+ PyObject *obFile;
+ FILE *pFile;
+ if (!PyArg_ParseTuple(args,"O!il:locking", &obFile, PyFile_Type, &mode, &nBytes))
+ return NULL;
+ if (NULL==(pFile = PyFile_AsFile(obFile)))
+ return NULL;
+ if (0 != _locking(_fileno(pFile), mode, nBytes))
+ return PyErr_SetFromErrno(PyExc_IOError);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+// Forces the malloc heap to clean itself up, and free unused blocks
+// back to the OS.
+static PyObject *msvcrt_heapmin(PyObject *self, PyObject *args)
+{
+ if (!PyArg_ParseTuple(args,":heapmin"))
+ return NULL;
+ if (_heapmin()!=0)
+ return PyErr_SetFromErrno(PyExc_MemoryError); // Is this the correct error???
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+/*******
+Left this out for now...
+
+// Convert an OS file handle to a Python file object (yay!).
+// This may only work on NT
+static PyObject *msvcrt_open_osfhandle(PyObject *self, PyObject *args)
+{
+ // Note that we get the underlying handle using the long
+ // "abstract" interface. This will allow either a native integer
+ // or else a Win32 extension PyHANDLE object, which implements an
+ // int() converter.
+ PyObject *obHandle;
+ PyObject *obInt;
+ int flags;
+ long handle;
+ if (!PyArg_ParseTuple(args,"Oi:open_osfhandle", &obHandle, &flags))
+ return NULL;
+
+ if (NULL==(obInt = PyNumber_Int(obHandle))) {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "The handle param must be an integer, =
+or an object able to be converted to an integer");
+ return NULL;
+ }
+ handle = PyInt_AsLong(obInt);
+ Py_DECREF(obInt);
+ rtHandle = _open_osfhandle(handle, flags);
+ if (rtHandle==-1)
+ return PyErr_SetFromErrno(PyExc_IOError);
+
+ what mode? Should I just return here, and expose _fdopen
+ and setvbuf?
+
+ f1=_fdopen(fd1, "w");
+ setvbuf(f1, NULL, _IONBF, 0);
+ f=PyFile_FromFile(f1, cmdstring, "w", fclose);
+
+}
+*****/
+
+/* List of functions exported by this module */
+static struct PyMethodDef msvcrt_functions[] = {
+ {"locking", msvcrt_locking, 1},
+ {"heapmin", msvcrt_heapmin, 1},
+ {NULL, NULL}
+};
+
+__declspec(dllexport) void
+initmsvcrt(void)
+{
+ Py_InitModule("msvcrt", msvcrt_functions);
+}