Index: Lib/test/test_mmap.py =================================================================== --- Lib/test/test_mmap.py (revision 69714) +++ Lib/test/test_mmap.py (working copy) @@ -417,6 +417,30 @@ m = mmap.mmap(f.fileno(), mapsize - halfsize, offset=halfsize) self.assertEqual(m[0:3], 'foo') f.close() + + # Try resizing map + try: + m.resize(512) + except SystemError: + # resize() not supported + # No messages are printed, since the output of this test suite + # would then be different across platforms. + pass + else: + # resize() is supported + self.assertEqual(len(m), 512) + # Check that we can no longer seek beyond the new size. + self.assertRaises(ValueError, m.seek, 513, 0) + # Check that the content is not changed + self.assertEqual(m[0:3], 'foo') + + # Check that the underlying file is truncated too + f = open(TESTFN) + f.seek(0, 2) + self.assertEqual(f.tell(), halfsize + 512) + f.close() + self.assertEqual(m.size(), halfsize + 512) + m.close() finally: Index: Modules/mmapmodule.c =================================================================== --- Modules/mmapmodule.c (revision 69714) +++ Modules/mmapmodule.c (working copy) @@ -444,7 +444,7 @@ off_lo = (DWORD)(self->offset & 0xFFFFFFFF); #else newSizeHigh = 0; - newSizeLow = (DWORD)new_size; + newSizeLow = (DWORD)(self->offset + new_size); off_hi = 0; off_lo = (DWORD)self->offset; #endif @@ -490,7 +490,7 @@ } else { void *newmap; - if (ftruncate(self->fd, new_size) == -1) { + if (ftruncate(self->fd, self->offset + new_size) == -1) { PyErr_SetFromErrno(mmap_module_error); return NULL; }