]> granicus.if.org Git - python/commitdiff
(Merge 3.1) Issue #11277: mmap.mmap() calls fcntl(fd, F_FULLFSYNC) on Mac OS X
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 3 May 2011 12:36:36 +0000 (14:36 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 3 May 2011 12:36:36 +0000 (14:36 +0200)
to get around a mmap bug with sparse files. Patch written by Steffen Daode
Nurpmeso.

Doc/library/mmap.rst
Misc/NEWS
Modules/mmapmodule.c

index 125b34f3c7f6fbbda2407e33003e9e9e9ad5e790..f036a60ce08a661dda0f1c5e523f319166ceb23b 100644 (file)
@@ -94,6 +94,10 @@ memory but does not update the underlying file.
    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 0030bab1a3060578dbd407c2748b434d5127c79a..50f6aaf526158846e7b20a2b981e6a810f290908 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -70,6 +70,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 #10761: Fix tarfile.extractall failure  when symlinked files are
   present. Initial patch by Scott Leerssen.
 
index e93acda19f4b2e8c880ee7783aba2000e0614b30..3078279f22346397dbec0cdfdb79d0092ed9056b 100644 (file)
@@ -23,6 +23,9 @@
 
 #ifndef MS_WINDOWS
 #define UNIX
+# ifdef __APPLE__
+#  include <fcntl.h>
+# endif
 #endif
 
 #ifdef MS_WINDOWS
@@ -1170,6 +1173,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 */