Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r88917:8c6ea1cc81e6
Date: 2016-12-06 19:08 +0000
http://bitbucket.org/pypy/pypy/changeset/8c6ea1cc81e6/
Log: Test (annoyingly slow) and fix for BZ2Decompressor.decompress() with
large max_length
diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py
--- a/pypy/module/bz2/interp_bz2.py
+++ b/pypy/module/bz2/interp_bz2.py
@@ -206,7 +206,11 @@
self.left = 0
def get_data_size(self):
- return self.current_size - rffi.getintfield(self.bzs, 'c_avail_out')
+ curr_out = self.current_size - rffi.getintfield(self.bzs,
'c_avail_out')
+ total_size = curr_out
+ for s in self.temp:
+ total_size += len(s)
+ return total_size
def _allocate_chunk(self, size):
self.raw_buf, self.gc_buf, self.case_num = rffi.alloc_buffer(size)
@@ -231,6 +235,8 @@
newsize = size
if self.max_length == -1:
newsize = _new_buffer_size(size)
+ else:
+ newsize = min(newsize, self.max_length - self.get_data_size())
self._allocate_chunk(newsize)
def make_result_string(self):
diff --git a/pypy/module/bz2/test/test_interpbz2.py
b/pypy/module/bz2/test/test_interpbz2.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/bz2/test/test_interpbz2.py
@@ -0,0 +1,16 @@
+import pytest
+import py
+from pypy.module.bz2.interp_bz2 import W_BZ2Decompressor, INITIAL_BUFFER_SIZE
+
[email protected]_fixture
+def w_decomp(space):
+ w_decomp = W_BZ2Decompressor(space)
+ yield w_decomp
+
[email protected]('size', [1234, INITIAL_BUFFER_SIZE, 12345])
+def test_decompress_max_length(space, w_decomp, size):
+ filename = py.path.local(__file__).new(basename='largetest.bz2')
+ with open(str(filename), 'rb') as f:
+ data = f.read()
+ result = w_decomp.decompress(data, size)
+ assert space.int_w(space.len(result)) == size
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit