summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-01 23:14:55 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-01 23:14:55 (GMT)
commitfadeeffe5b7184c5406ee64e46550bc90395e8f7 (patch)
treeb7620443dd89163ec692797ecc6406ff6b808651
parent47583fa9b4113accd43efc8c205586cd956405a6 (diff)
parent8108e96bc811eeb61594e398848d25cbe9efbffe (diff)
downloadcpython-fadeeffe5b7184c5406ee64e46550bc90395e8f7.zip
cpython-fadeeffe5b7184c5406ee64e46550bc90395e8f7.tar.gz
cpython-fadeeffe5b7184c5406ee64e46550bc90395e8f7.tar.bz2
(Merge 3.2) Issue #11277: mmap.mmap() calls fcntl(fd, F_FULLFSYNC) on Mac OS X
to get around a mmap bug with sparse files. Patch written by Steffen Daode Nurpmeso.
-rw-r--r--Doc/library/mmap.rst4
-rw-r--r--Lib/test/test_zlib.py2
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/mmapmodule.c9
4 files changed, 17 insertions, 1 deletions
diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst
index 128bc90..7a901c9 100644
--- a/Doc/library/mmap.rst
+++ b/Doc/library/mmap.rst
@@ -86,6 +86,10 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
defaults to 0. *offset* must be a multiple of the PAGESIZE or
ALLOCATIONGRANULARITY.
+ To ensure validity of the created memory mapping the file specified
+ by the descriptor *fileno* is internally automatically synchronized
+ with physical backing store on Mac OS X and OpenVMS.
+
This example shows a simple way of using :class:`mmap`::
import mmap
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index 5d38d97..9aafffa 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -70,7 +70,7 @@ class ChecksumBigBufferTestCase(unittest.TestCase):
with open(support.TESTFN, "wb+") as f:
f.seek(_4G)
f.write(b"asdf")
- with open(support.TESTFN, "rb") as f:
+ f.flush()
self.mapping = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
def tearDown(self):
diff --git a/Misc/NEWS b/Misc/NEWS
index 39d3da4..842b87b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -132,6 +132,9 @@ Core and Builtins
Library
-------
+- Issue #11277: mmap.mmap() calls fcntl(fd, F_FULLFSYNC) on Mac OS X to get
+ around a mmap bug with sparse files. Patch written by Steffen Daode Nurpmeso.
+
- Issue #8407: Add signal.pthread_sigmask() function to fetch and/or change the
signal mask of the calling thread.
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index fdf3922..36ca67d 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -23,6 +23,9 @@
#ifndef MS_WINDOWS
#define UNIX
+# ifdef __APPLE__
+# include <fcntl.h>
+# endif
#endif
#ifdef MS_WINDOWS
@@ -1122,6 +1125,12 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
"mmap invalid access parameter.");
}
+#ifdef __APPLE__
+ /* Issue #11277: fsync(2) is not enough on OS X - a special, OS X specific
+ fcntl(2) is necessary to force DISKSYNC and get around mmap(2) bug */
+ if (fd != -1)
+ (void)fcntl(fd, F_FULLFSYNC);
+#endif
#ifdef HAVE_FSTAT
# ifdef __VMS
/* on OpenVMS we must ensure that all bytes are written to the file */