[Python-checkins] CVS: python/dist/src/Modules fcntlmodule.c,2.28,2.29

Fred L. Drake fdrake@users.sourceforge.net
Wed, 09 May 2001 14:02:04 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv23294/Modules

Modified Files:
	fcntlmodule.c 
Log Message:

Modify to allow file objects wherever file descriptors are needed.
This closes SF bug #231328.

Added all constants needed to use the functions defined in this module
that are not defined elsewhere (the O_* symbols are available in the
os module).  No additonal modules are needed to use this now.


Index: fcntlmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/fcntlmodule.c,v
retrieving revision 2.28
retrieving revision 2.29
diff -C2 -r2.28 -r2.29
*** fcntlmodule.c	2001/01/25 10:10:39	2.28
--- fcntlmodule.c	2001/05/09 21:02:02	2.29
***************
*** 16,19 ****
--- 16,31 ----
  
  
+ static int
+ conv_descriptor(PyObject *object, int *target)
+ {
+     int fd = PyObject_AsFileDescriptor(object);
+ 
+     if (fd < 0)
+         return 0;
+     *target = fd;
+     return 1;
+ }
+ 
+ 
  /* fcntl(fd, opt, [arg]) */
  
***************
*** 29,33 ****
  	char buf[1024];
  
! 	if (PyArg_ParseTuple(args, "iis#:fcntl", &fd, &code, &str, &len)) {
  		if (len > sizeof buf) {
  			PyErr_SetString(PyExc_ValueError,
--- 41,46 ----
  	char buf[1024];
  
! 	if (PyArg_ParseTuple(args, "O&is#:fcntl",
!                              conv_descriptor, &fd, &code, &str, &len)) {
  		if (len > sizeof buf) {
  			PyErr_SetString(PyExc_ValueError,
***************
*** 48,53 ****
  	PyErr_Clear();
  	arg = 0;
! 	if (!PyArg_ParseTuple(args, "ii|i;fcntl requires 2 integers and optionally a third integer or a string", 
! 			      &fd, &code, &arg)) {
  	  return NULL;
  	}
--- 61,68 ----
  	PyErr_Clear();
  	arg = 0;
! 	if (!PyArg_ParseTuple(args,
!              "O&i|i;fcntl requires a file or file descriptor,"
!              " an integer and optionally a third integer or a string", 
! 			      conv_descriptor, &fd, &code, &arg)) {
  	  return NULL;
  	}
***************
*** 90,94 ****
  	char buf[1024];
  
! 	if (PyArg_ParseTuple(args, "iis#:ioctl", &fd, &code, &str, &len)) {
  		if (len > sizeof buf) {
  			PyErr_SetString(PyExc_ValueError,
--- 105,110 ----
  	char buf[1024];
  
! 	if (PyArg_ParseTuple(args, "O&is#:ioctl",
!                              conv_descriptor, &fd, &code, &str, &len)) {
  		if (len > sizeof buf) {
  			PyErr_SetString(PyExc_ValueError,
***************
*** 109,114 ****
  	PyErr_Clear();
  	arg = 0;
! 	if (!PyArg_ParseTuple(args, "ii|i;ioctl requires 2 integers and optionally a third integer or a string", 
! 			      &fd, &code, &arg)) {
  	  return NULL;
  	}
--- 125,130 ----
  	PyErr_Clear();
  	arg = 0;
! 	if (!PyArg_ParseTuple(args, "O&i|i;ioctl requires 2 integers and optionally a third integer or a string",
! 			      conv_descriptor, &fd, &code, &arg)) {
  	  return NULL;
  	}
***************
*** 146,150 ****
  	int ret;
  
! 	if (!PyArg_ParseTuple(args, "ii:flock", &fd, &code))
  		return NULL;
  
--- 162,167 ----
  	int ret;
  
! 	if (!PyArg_ParseTuple(args, "O&i:flock",
!                               conv_descriptor, &fd, &code))
  		return NULL;
  
***************
*** 203,207 ****
  	PyObject *lenobj = NULL, *startobj = NULL;
  
! 	if (!PyArg_ParseTuple(args, "ii|OOi:lockf", &fd, &code,
  			      &lenobj, &startobj, &whence))
  	    return NULL;
--- 220,225 ----
  	PyObject *lenobj = NULL, *startobj = NULL;
  
! 	if (!PyArg_ParseTuple(args, "O&i|OOi:lockf",
!                               conv_descriptor, &fd, &code,
  			      &lenobj, &startobj, &whence))
  	    return NULL;
***************
*** 325,328 ****
--- 343,391 ----
          if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1;
          if (ins(d, "LOCK_UN", (long)LOCK_UN)) return -1;
+ #ifdef F_DUPFD
+         if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1;
+ #endif
+ #ifdef F_GETFD
+         if (ins(d, "F_GETFD", (long)F_GETFD)) return -1;
+ #endif
+ #ifdef F_SETFD
+         if (ins(d, "F_SETFD", (long)F_SETFD)) return -1;
+ #endif
+ #ifdef F_GETFL
+         if (ins(d, "F_GETFL", (long)F_GETFL)) return -1;
+ #endif
+ #ifdef F_SETFL
+         if (ins(d, "F_SETFL", (long)F_SETFL)) return -1;
+ #endif
+ #ifdef F_GETLK
+         if (ins(d, "F_GETLK", (long)F_GETLK)) return -1;
+ #endif
+ #ifdef F_SETLK
+         if (ins(d, "F_SETLK", (long)F_SETLK)) return -1;
+ #endif
+ #ifdef F_SETLKW
+         if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1;
+ #endif
+ #ifdef F_GETOWN
+         if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1;
+ #endif
+ #ifdef F_SETOWN
+         if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1;
+ #endif
+ #ifdef F_GETSIG
+         if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1;
+ #endif
+ #ifdef F_SETSIG
+         if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1;
+ #endif
+ #ifdef F_RDLCK
+         if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1;
+ #endif
+ #ifdef F_WRLCK
+         if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1;
+ #endif
+ #ifdef F_UNLCK
+         if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1;
+ #endif
  	return 0;
  }