[Python-checkins] CVS: python/dist/src/PC msvcrtmodule.c,1.5,1.6

Tim Peters python-dev@python.org
Mon, 11 Dec 2000 17:58:59 -0800


Update of /cvsroot/python/python/dist/src/PC
In directory slayer.i.sourceforge.net:/tmp/cvs-serv17191/python/dist/src/pc

Modified Files:
	msvcrtmodule.c 
Log Message:
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Still needs docs; see bug report (which was reassigned to Fred) for MS's docs.


Index: msvcrtmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/msvcrtmodule.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** msvcrtmodule.c	2000/06/30 17:48:51	1.5
--- msvcrtmodule.c	2000/12/12 01:58:56	1.6
***************
*** 19,26 ****
  #include "Python.h"
  #include "malloc.h"
  
  // Force the malloc heap to clean itself up, and free unused blocks
  // back to the OS.  (According to the docs, only works on NT.)
! static PyObject *msvcrt_heapmin(PyObject *self, PyObject *args)
  {
  	if (!PyArg_ParseTuple(args, ":heapmin"))
--- 19,30 ----
  #include "Python.h"
  #include "malloc.h"
+ #include <io.h>
+ #include <conio.h>
+ #include <sys/locking.h>
  
  // Force the malloc heap to clean itself up, and free unused blocks
  // back to the OS.  (According to the docs, only works on NT.)
! static PyObject *
! msvcrt_heapmin(PyObject *self, PyObject *args)
  {
  	if (!PyArg_ParseTuple(args, ":heapmin"))
***************
*** 35,39 ****
  
  // Perform locking operations on a C runtime file descriptor.
! static PyObject *msvcrt_locking(PyObject *self, PyObject *args)
  {
  	int fd;
--- 39,44 ----
  
  // Perform locking operations on a C runtime file descriptor.
! static PyObject *
! msvcrt_locking(PyObject *self, PyObject *args)
  {
  	int fd;
***************
*** 56,60 ****
  
  // Set the file translation mode for a C runtime file descriptor.
! static PyObject *msvcrt_setmode(PyObject *self, PyObject *args)
  {
  	int fd;
--- 61,66 ----
  
  // Set the file translation mode for a C runtime file descriptor.
! static PyObject *
! msvcrt_setmode(PyObject *self, PyObject *args)
  {
  	int fd;
***************
*** 71,75 ****
  
  // Convert an OS file handle to a C runtime file descriptor.
! static PyObject *msvcrt_open_osfhandle(PyObject *self, PyObject *args)
  {
  	long handle;
--- 77,82 ----
  
  // Convert an OS file handle to a C runtime file descriptor.
! static PyObject *
! msvcrt_open_osfhandle(PyObject *self, PyObject *args)
  {
  	long handle;
***************
*** 88,92 ****
  
  // Convert a C runtime file descriptor to an OS file handle.
! static PyObject *msvcrt_get_osfhandle(PyObject *self, PyObject *args)
  {
  	int fd;
--- 95,100 ----
  
  // Convert a C runtime file descriptor to an OS file handle.
! static PyObject *
! msvcrt_get_osfhandle(PyObject *self, PyObject *args)
  {
  	int fd;
***************
*** 107,113 ****
  
  /* Console I/O */
- #include <conio.h>
  
! static PyObject *msvcrt_kbhit(PyObject *self, PyObject *args)
  {
  	int ok;
--- 115,121 ----
  
  /* Console I/O */
  
! static PyObject *
! msvcrt_kbhit(PyObject *self, PyObject *args)
  {
  	int ok;
***************
*** 120,124 ****
  }
  
! static PyObject *msvcrt_getch(PyObject *self, PyObject *args)
  {
  	int ch;
--- 128,133 ----
  }
  
! static PyObject *
! msvcrt_getch(PyObject *self, PyObject *args)
  {
  	int ch;
***************
*** 135,139 ****
  }
  
! static PyObject *msvcrt_getche(PyObject *self, PyObject *args)
  {
  	int ch;
--- 144,149 ----
  }
  
! static PyObject *
! msvcrt_getche(PyObject *self, PyObject *args)
  {
  	int ch;
***************
*** 150,154 ****
  }
  
! static PyObject *msvcrt_putch(PyObject *self, PyObject *args)
  {
  	char ch;
--- 160,165 ----
  }
  
! static PyObject *
! msvcrt_putch(PyObject *self, PyObject *args)
  {
  	char ch;
***************
*** 162,166 ****
  }
  
! static PyObject *msvcrt_ungetch(PyObject *self, PyObject *args)
  {
  	char ch;
--- 173,178 ----
  }
  
! static PyObject *
! msvcrt_ungetch(PyObject *self, PyObject *args)
  {
  	char ch;
***************
*** 176,179 ****
--- 188,206 ----
  
  
+ static void
+ insertint(PyObject *d, char *name, int value)
+ {
+ 	PyObject *v = PyInt_FromLong((long) value);
+ 	if (v == NULL) {
+ 		/* Don't bother reporting this error */
+ 		PyErr_Clear();
+ 	}
+ 	else {
+ 		PyDict_SetItemString(d, name, v);
+ 		Py_DECREF(v);
+ 	}
+ }
+ 
+ 
  /* List of functions exported by this module */
  static struct PyMethodDef msvcrt_functions[] = {
***************
*** 194,197 ****
  initmsvcrt(void)
  {
! 	Py_InitModule("msvcrt", msvcrt_functions);
  }
--- 221,232 ----
  initmsvcrt(void)
  {
! 	PyObject *m = Py_InitModule("msvcrt", msvcrt_functions);
! 	PyObject *d = PyModule_GetDict(m);
! 
! 	/* 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);
  }