summaryrefslogtreecommitdiffstats
path: root/PC/msvcrtmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-07 00:11:34 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-07 00:11:34 (GMT)
commit29c1ea5af0b9d309c1342db5b75f5e0c7618e8e7 (patch)
tree8a06d2a10367a7a09a1a77351109b42ccc0e96c8 /PC/msvcrtmodule.c
parentfb84255e6756adcb4c38e23d63c0f3c017012789 (diff)
downloadcpython-29c1ea5af0b9d309c1342db5b75f5e0c7618e8e7.zip
cpython-29c1ea5af0b9d309c1342db5b75f5e0c7618e8e7.tar.gz
cpython-29c1ea5af0b9d309c1342db5b75f5e0c7618e8e7.tar.bz2
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 0000000..dec6285
--- /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);
+}