Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8108e96

Browse files
author
Victor Stinner
committed
(Merge 3.1) 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.
2 parents cee01bf + a6cd0cf commit 8108e96

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

Doc/library/mmap.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
8686
defaults to 0. *offset* must be a multiple of the PAGESIZE or
8787
ALLOCATIONGRANULARITY.
8888

89+
To ensure validity of the created memory mapping the file specified
90+
by the descriptor *fileno* is internally automatically synchronized
91+
with physical backing store on Mac OS X and OpenVMS.
92+
8993
This example shows a simple way of using :class:`mmap`::
9094

9195
import mmap

Lib/test/test_zlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def setUp(self):
7070
with open(support.TESTFN, "wb+") as f:
7171
f.seek(_4G)
7272
f.write(b"asdf")
73-
with open(support.TESTFN, "rb") as f:
73+
f.flush()
7474
self.mapping = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
7575

7676
def tearDown(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ Core and Builtins
7979
Library
8080
-------
8181

82+
- Issue #11277: mmap.mmap() calls fcntl(fd, F_FULLFSYNC) on Mac OS X to get
83+
around a mmap bug with sparse files. Patch written by Steffen Daode Nurpmeso.
84+
8285
- Issue #11858: configparser.ExtendedInterpolation expected lower-case section
8386
names.
8487

Modules/mmapmodule.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
#ifndef MS_WINDOWS
2525
#define UNIX
26+
# ifdef __APPLE__
27+
# include <fcntl.h>
28+
# endif
2629
#endif
2730

2831
#ifdef MS_WINDOWS
@@ -1122,6 +1125,12 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
11221125
"mmap invalid access parameter.");
11231126
}
11241127

1128+
#ifdef __APPLE__
1129+
/* Issue #11277: fsync(2) is not enough on OS X - a special, OS X specific
1130+
fcntl(2) is necessary to force DISKSYNC and get around mmap(2) bug */
1131+
if (fd != -1)
1132+
(void)fcntl(fd, F_FULLFSYNC);
1133+
#endif
11251134
#ifdef HAVE_FSTAT
11261135
# ifdef __VMS
11271136
/* on OpenVMS we must ensure that all bytes are written to the file */

0 commit comments

Comments
 (0)