--- Modules/mmapmodule.c.~1~ 2008-08-19 10:47:13.000000000 -0700 +++ Modules/mmapmodule.c 2008-12-17 00:12:31.000000000 -0800 @@ -85,12 +85,24 @@ ACCESS_COPY } access_mode; +/* Our very own off_t-like type, 64-bit if possible */ +/* copied from Objects/fileobject.c */ +#if !defined(HAVE_LARGEFILE_SUPPORT) +typedef off_t Py_off_t; +#elif SIZEOF_OFF_T >= 8 +typedef off_t Py_off_t; +#elif SIZEOF_FPOS_T >= 8 +typedef fpos_t Py_off_t; +#else +#error "Large file support, but neither off_t nor fpos_t is large enough." +#endif + typedef struct { PyObject_HEAD char * data; size_t size; size_t pos; /* relative to offset */ - size_t offset; + Py_off_t offset; #ifdef MS_WINDOWS HANDLE map_handle; @@ -1078,7 +1090,8 @@ #endif mmap_object *m_obj; PyObject *map_size_obj = NULL, *offset_obj = NULL; - Py_ssize_t map_size, offset; + Py_ssize_t map_size; + Py_off_t offset; int fd, flags = MAP_SHARED, prot = PROT_WRITE | PROT_READ; int devzero = -1; int access = (int)ACCESS_DEFAULT; @@ -1093,7 +1106,20 @@ map_size = _GetMapSize(map_size_obj, "size"); if (map_size < 0) return NULL; - offset = _GetMapSize(offset_obj, "offset"); + if (offset_obj == Py_None || offset_obj == NULL) { + offset = 0; + } + else { +#if !defined(HAVE_LARGEFILE_SUPPORT) + offset = PyInt_AsLong(offset_obj); +#else + offset = PyLong_Check(offset_obj) ? + PyLong_AsLongLong(offset_obj) : + PyInt_AsLong(offset_obj); +#endif + if (PyErr_Occurred()) + return NULL; + } if (offset < 0) return NULL; @@ -1136,7 +1162,7 @@ if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) { if (map_size == 0) { map_size = st.st_size; - } else if ((size_t)offset + (size_t)map_size > st.st_size) { + } else if (offset + map_size > st.st_size) { PyErr_SetString(PyExc_ValueError, "mmap length is greater than file size"); return NULL;