summaryrefslogtreecommitdiff
path: root/smmap
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-07 16:57:50 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-07 16:57:50 +0100
commitf071ffdcacbafff648cd29d6f75fe27c47f53210 (patch)
tree6bc8f7657e50f65a7e0c43fc5c4de5f34abc6e41 /smmap
parent70fae1f98bb7d44b58d94a183e9eb8b590bc23bf (diff)
downloadsmmap-f071ffdcacbafff648cd29d6f75fe27c47f53210.tar.gz
All tests work, bumped version
Diffstat (limited to 'smmap')
-rw-r--r--smmap/__init__.py2
-rw-r--r--smmap/buf.py5
-rw-r--r--smmap/mman.py7
-rw-r--r--smmap/test/test_buf.py3
4 files changed, 13 insertions, 4 deletions
diff --git a/smmap/__init__.py b/smmap/__init__.py
index 46b0002..e711bbb 100644
--- a/smmap/__init__.py
+++ b/smmap/__init__.py
@@ -3,7 +3,7 @@
__author__ = "Sebastian Thiel"
__contact__ = "byronimo@gmail.com"
__homepage__ = "https://github.com/Byron/smmap"
-version_info = (0, 8, 5)
+version_info = (0, 9, 0)
__version__ = '.'.join(str(i) for i in version_info)
# make everything available in root package for convenience
diff --git a/smmap/buf.py b/smmap/buf.py
index b3b71c4..e6f2434 100644
--- a/smmap/buf.py
+++ b/smmap/buf.py
@@ -93,6 +93,7 @@ class SlidingWindowMapBuffer(object):
l -= len(d)
# This is slower than the join ... but what can we do ...
out += d
+ del(d)
# END while there are bytes to read
return out
else:
@@ -103,6 +104,10 @@ class SlidingWindowMapBuffer(object):
d = c.buffer()[:l]
ofs += len(d)
l -= len(d)
+ # Make sure we don't keep references, as c.use_region() might attempt to free resources, but
+ # can't unless we use pure bytes
+ if hasattr(d, 'tobytes'):
+ d = d.tobytes()
md.append(d)
# END while there are bytes to read
return bytes().join(md)
diff --git a/smmap/mman.py b/smmap/mman.py
index 6e8b9ee..7180c75 100644
--- a/smmap/mman.py
+++ b/smmap/mman.py
@@ -58,7 +58,7 @@ class WindowCursor(object):
# Free all resources associated with the mapped file
self._manager._fdict.pop(self._rlist.path_or_fd())
# END remove regions list from manager
- except TypeError:
+ except (TypeError, KeyError):
# sometimes, during shutdown, getrefcount is None. Its possible
# to re-import it, however, its probably better to just ignore
# this python problem (for now).
@@ -70,11 +70,14 @@ class WindowCursor(object):
def _copy_from(self, rhs):
"""Copy all data from rhs into this instance, handles usage count"""
self._manager = rhs._manager
- self._rlist = rhs._rlist
+ self._rlist = type(rhs._rlist)(rhs._rlist)
self._region = rhs._region
self._ofs = rhs._ofs
self._size = rhs._size
+ for region in self._rlist:
+ region.increment_client_count()
+
if self._region is not None:
self._region.increment_client_count()
# END handle regions
diff --git a/smmap/test/test_buf.py b/smmap/test/test_buf.py
index 0337715..984b432 100644
--- a/smmap/test/test_buf.py
+++ b/smmap/test/test_buf.py
@@ -12,7 +12,6 @@ from random import randint
from time import time
import sys
import os
-import logging
man_optimal = SlidingWindowMapManager()
@@ -104,6 +103,7 @@ class TestBuf(TestBase):
assert len(d) == ofs_end - ofs_start
assert d == data[ofs_start:ofs_end]
num_bytes += len(d)
+ del d
else:
pos = randint(0, fsize)
assert buf[pos] == data[pos]
@@ -122,6 +122,7 @@ class TestBuf(TestBase):
% (man_id, max_num_accesses, mode_str, type(item), num_bytes / mb, elapsed, (num_bytes / mb) / elapsed),
file=sys.stderr)
# END handle access mode
+ del buf
# END for each manager
# END for each input
os.close(fd)