[Python-checkins] CVS: python/dist/src/Modules mmapmodule.c,2.10,2.11

A.M. Kuchling python-dev@python.org
Sat, 17 Jun 2000 15:41:24 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv2060

Modified Files:
	mmapmodule.c 
Log Message:
Fix the size() method to return the size of the file on Unix, not the 
size of the mapped area.  This seems to be what the Windows version does.
This change requires keeping around the fd of the mapped file.


Index: mmapmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mmapmodule.c,v
retrieving revision 2.10
retrieving revision 2.11
diff -C2 -r2.10 -r2.11
*** mmapmodule.c	2000/06/03 20:43:43	2.10
--- mmapmodule.c	2000/06/17 22:41:22	2.11
***************
*** 30,33 ****
--- 30,34 ----
  #include <unistd.h>
  #include <sys/mman.h>
+ #include <sys/stat.h>
  #endif
  
***************
*** 50,54 ****
  
  #ifdef UNIX
!   /* No Unix-specific information at this point in time */
  #endif
  } mmap_object;
--- 51,55 ----
  
  #ifdef UNIX
!         int fd;
  #endif
  } mmap_object;
***************
*** 211,215 ****
  static PyObject *
  mmap_write_method (mmap_object * self,
! 		       PyObject * args)
  {
  	long length;
--- 212,216 ----
  static PyObject *
  mmap_write_method (mmap_object * self,
! 		   PyObject * args)
  {
  	long length;
***************
*** 265,269 ****
  
  #ifdef UNIX
! 	return (Py_BuildValue ("l", self->size) );
  #endif /* UNIX */
  }
--- 266,277 ----
  
  #ifdef UNIX
! 	{
! 		struct stat buf;
! 		if (-1 == fstat(self->fd, &buf)) {
! 			PyErr_SetFromErrno(mmap_module_error);
! 			return NULL;
! 		}
! 		return (Py_BuildValue ("l", buf.st_size) );
! 	}
  #endif /* UNIX */
  }
***************
*** 718,721 ****
--- 726,730 ----
  	m_obj->size = (size_t) map_size;
  	m_obj->pos = (size_t) 0;
+ 	m_obj->fd = fd;
  	m_obj->data = mmap(NULL, map_size, 
  			   prot, flags,