f.flush ()
return mmap.mmap (f.fileno(), 0)
+ def test_empty_file (self):
+ f = open (TESTFN, 'w+b')
+ f.close()
+ f = open(TESTFN, "rb")
+ self.assertRaisesRegex(ValueError,
+ "cannot mmap an empty file",
+ mmap.mmap, f.fileno(), 0, access=mmap.ACCESS_READ)
+ f.close()
+
def test_offset (self):
f = open (TESTFN, 'w+b')
Extension Modules
-----------------
+- Issue #15676: Now "mmap" check for empty files before doing the
+ offset check. Patch by Steven Willis.
+
- Issue #6493: An issue in ctypes on Windows that caused structure bitfields
of type ctypes.c_uint32 and width 32 to incorrectly be set has been fixed.
if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
if (map_size == 0) {
off_t calc_size;
+ if (st.st_size == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot mmap an empty file");
+ return NULL;
+ }
if (offset >= st.st_size) {
PyErr_SetString(PyExc_ValueError,
"mmap offset is greater than file size");