summaryrefslogtreecommitdiff
path: root/numpy/core/memmap.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2009-04-12 23:32:41 +0000
committerCharles Harris <charlesr.harris@gmail.com>2009-04-12 23:32:41 +0000
commitd673c50ccfe30f0b97de2d853e20fdc191a3fe30 (patch)
treea47ea60820aee718832829d245efecd75f933528 /numpy/core/memmap.py
parent2fbfbcf3ec688539f7dd30e0a3afafa7929b213b (diff)
downloadnumpy-d673c50ccfe30f0b97de2d853e20fdc191a3fe30.tar.gz
Fix memmap for python >= 2.6 by making offset multiple of
ALLOCATIONGRANULARITY.
Diffstat (limited to 'numpy/core/memmap.py')
-rw-r--r--numpy/core/memmap.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index 05bfd68b7..5c8542479 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -226,14 +226,16 @@ class memmap(ndarray):
if sys.version_info[:2] >= (2,6):
# The offset keyword in mmap.mmap needs Python >= 2.6
- bytes = bytes - offset
- mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=offset)
- self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
- offset=0, order=order)
+ blocks = offset // mmap.ALLOCATIONGRANULARITY
+ aligned_offset = blocks * mmap.ALLOCATIONGRANULARITY
+ bytes = bytes - aligned_offset
+ offset = offset - aligned_offset
+ mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=aligned_offset)
else:
mm = mmap.mmap(fid.fileno(), bytes, access=acc)
- self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
- offset=offset, order=order)
+
+ self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
+ offset=offset, order=order)
self._mmap = mm
return self