Patchwork D7808: mmap: add a size argument to mmapread

login
register
mail settings
Submitter phabricator
Date Jan. 8, 2020, 8:04 p.m.
Message ID <d23689499ded18e23d9cd2759e61e38b@localhost.localdomain>
Download mbox | patch
Permalink /patch/44215/
State Not Applicable
Headers show

Comments

phabricator - Jan. 8, 2020, 8:04 p.m.
Closed by commit rHG8ed8dfbeabb9: mmap: add a size argument to mmapread (authored by marmoute).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D7808?vs=19060&id=19109#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7808?vs=19060&id=19109

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7808/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7808

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: durin42, mharbison72, mercurial-devel

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -415,10 +415,16 @@ 
         return data
 
 
-def mmapread(fp):
+def mmapread(fp, size=None):
+    if size == 0:
+        # size of 0 to mmap.mmap() means "all data"
+        # rather than "zero bytes", so special case that.
+        return b''
+    elif size is None:
+        size = 0
     try:
         fd = getattr(fp, 'fileno', lambda: fp)()
-        return mmap.mmap(fd, 0, access=mmap.ACCESS_READ)
+        return mmap.mmap(fd, size, access=mmap.ACCESS_READ)
     except ValueError:
         # Empty files cannot be mmapped, but mmapread should still work.  Check
         # if the file is empty, and if so, return an empty buffer.