Author: Brian Kearns <[email protected]>
Branch:
Changeset: r62542:16d366c59499
Date: 2013-03-20 01:42 -0400
http://bitbucket.org/pypy/pypy/changeset/16d366c59499/
Log: cleanup unmap/unmapview/unmap_range, skip unmap_range test on non-
posix
diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py
--- a/rpython/rlib/rmmap.py
+++ b/rpython/rlib/rmmap.py
@@ -287,20 +287,26 @@
self.data = data
self.size = size
- def unmap_range(self, offset, size):
- """Unmap (a portion of) the mapped range. POSIX only.
+ def unmap(self):
+ if _MS_WINDOWS:
+ UnmapViewOfFile(self.getptr(0))
+ elif _POSIX:
+ self.unmap_range(0, self.size)
- Per munmap(1), the offset must be a multiple of the page size,
- and the size will be rounded up to a multiple of the page size.
- """
- assert _POSIX
- return c_munmap_safe(self.getptr(offset), size)
+ if _POSIX:
+ def unmap_range(self, offset, size):
+ """Unmap (a portion of) the mapped range.
+
+ Per munmap(1), the offset must be a multiple of the page size,
+ and the size will be rounded up to a multiple of the page size.
+ """
+ c_munmap_safe(self.getptr(offset), size)
def close(self):
+ if self.size > 0:
+ self.unmap()
+ self.setdata(NODATA, 0)
if _MS_WINDOWS:
- if self.size > 0:
- self.unmapview()
- self.setdata(NODATA, 0)
if self.map_handle != INVALID_HANDLE:
rwin32.CloseHandle(self.map_handle)
self.map_handle = INVALID_HANDLE
@@ -315,16 +321,10 @@
# underlaying close error code
os.close(self.fd)
self.fd = -1
- if self.size > 0:
- self.unmap_range(0, self.size)
- self.setdata(NODATA, 0)
def __del__(self):
self.close()
- def unmapview(self):
- UnmapViewOfFile(self.getptr(0))
-
def read_byte(self):
self.check_valid()
@@ -536,7 +536,7 @@
self.setdata(newdata, newsize)
elif _MS_WINDOWS:
# disconnect the mapping
- self.unmapview()
+ self.unmap()
rwin32.CloseHandle(self.map_handle)
# move to the desired EOF position
diff --git a/rpython/rlib/test/test_rmmap.py b/rpython/rlib/test/test_rmmap.py
--- a/rpython/rlib/test/test_rmmap.py
+++ b/rpython/rlib/test/test_rmmap.py
@@ -65,8 +65,9 @@
f.close()
- def test_unmap(self):
- f = open(self.tmpname + "-unmap", "w+")
+ @py.test.mark.skipif("os.name != 'posix'")
+ def test_unmap_range(self):
+ f = open(self.tmpname + "-unmap-range", "w+")
left, right, size = 100, 200, 500 # in pages
f.write(size*4096*"c")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit