Show More
@@ -485,15 +485,24 def mmapread(fp, size=None, pre_populate | |||
|
485 | 485 | elif size is None: |
|
486 | 486 | size = 0 |
|
487 | 487 | fd = getattr(fp, 'fileno', lambda: fp)() |
|
488 | ||
|
489 | if pycompat.iswindows: | |
|
490 | _mmap = lambda fd, size: mmap.mmap(fd, size, access=mmap.ACCESS_READ) | |
|
491 | else: | |
|
488 | 492 | flags = mmap.MAP_PRIVATE |
|
489 | 493 | bg_populate = hasattr(osutil, "background_mmap_populate") |
|
494 | ||
|
490 | 495 | if pre_populate and not bg_populate: |
|
491 | 496 | flags |= getattr(mmap, 'MAP_POPULATE', 0) |
|
492 | try: | |
|
497 | ||
|
498 | def _mmap(fd, size) -> mmap.mmap: | |
|
493 | 499 | m = mmap.mmap(fd, size, flags=flags, prot=mmap.PROT_READ) |
|
494 | 500 | if pre_populate and bg_populate: |
|
495 | 501 | osutil.background_mmap_populate(m) |
|
496 | 502 | return m |
|
503 | ||
|
504 | try: | |
|
505 | return _mmap(fd, size) | |
|
497 | 506 | except ValueError: |
|
498 | 507 | # Empty files cannot be mmapped, but mmapread should still work. Check |
|
499 | 508 | # if the file is empty, and if so, return an empty buffer. |
General Comments 0
You need to be logged in to leave comments.
Login now