]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #11277: mmap calls fcntl(fd, F_FULLFSYNC) on Mac OS X to get around a
authorVictor Stinner <victor.stinner@haypocalc.com>
Sun, 1 May 2011 23:05:37 +0000 (01:05 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sun, 1 May 2011 23:05:37 +0000 (01:05 +0200)
mmap bug with sparse files. Patch written by Steffen Daode Nurpmeso.

Doc/library/mmap.rst
Lib/test/test_zlib.py
Misc/NEWS
Modules/mmapmodule.c

index 5001d4f55ebe92b928be7229236454d28d7fc1e3..e061088a6982a64fc84b6bcefb2c4819a0574aed 100644 (file)
@@ -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
index 48ac40a4f7fbef3a869e6dc8b84cc558566ef33a..7593c064b01ac70b2adeb24cf2e30f842367cc93 100644 (file)
@@ -74,7 +74,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):
index 67a4bb395c781ab37beb6f74e1d19a2bc7a4f6e9..887861261fde986743cd2b9f046f2cc410ac03fa 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,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 #11763: don't use difflib in TestCase.assertMultiLineEqual if the
   strings are too long.
 
index f484a7a75bce5a5687b6a012f625a8687e8323cd..88da4a0ac647033a56f0636a2deded0e10539c4c 100644 (file)
@@ -23,6 +23,9 @@
 
 #ifndef MS_WINDOWS
 #define UNIX
+# ifdef __APPLE__
+#  include <fcntl.h>
+# endif
 #endif
 
 #ifdef MS_WINDOWS
@@ -1091,6 +1094,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 */