diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2000-06-17 22:41:22 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2000-06-17 22:41:22 (GMT) |
commit | 7b9fb92932ff1d501229263a69a4434558b0271d (patch) | |
tree | 47917763359d622e70605513ce3367fcb269255b /Modules | |
parent | b8050697b81425a154c20927f39d4ade3d84b7b9 (diff) | |
download | cpython-7b9fb92932ff1d501229263a69a4434558b0271d.zip cpython-7b9fb92932ff1d501229263a69a4434558b0271d.tar.gz cpython-7b9fb92932ff1d501229263a69a4434558b0271d.tar.bz2 |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/mmapmodule.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 1f5e19a..4bfcb21 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -29,6 +29,7 @@ #ifdef UNIX #include <unistd.h> #include <sys/mman.h> +#include <sys/stat.h> #endif #include <string.h> @@ -49,7 +50,7 @@ typedef struct { #endif #ifdef UNIX - /* No Unix-specific information at this point in time */ + int fd; #endif } mmap_object; @@ -210,7 +211,7 @@ mmap_find_method (mmap_object *self, static PyObject * mmap_write_method (mmap_object * self, - PyObject * args) + PyObject * args) { long length; char * data; @@ -264,7 +265,14 @@ mmap_size_method (mmap_object * self, #endif /* MS_WIN32 */ #ifdef UNIX - return (Py_BuildValue ("l", self->size) ); + { + 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 */ } @@ -717,6 +725,7 @@ new_mmap_object (PyObject * self, PyObject * args, PyObject *kwdict) if (m_obj == NULL) {return NULL;} 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, fd, 0); |