[pypy-commit] pypy default: Initialize rzlib stream in factory function. This should fix translation.

mjacob pypy.commits at gmail.com
Tue Feb 5 19:58:21 EST 2019


Author: Manuel Jacob <me at manueljacob.de>
Branch: 
Changeset: r95851:c5c3ad13d149
Date: 2019-02-06 01:43 +0100
http://bitbucket.org/pypy/pypy/changeset/c5c3ad13d149/

Log:	Initialize rzlib stream in factory function. This should fix
	translation.

diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py
--- a/pypy/module/zlib/interp_zlib.py
+++ b/pypy/module/zlib/interp_zlib.py
@@ -134,21 +134,8 @@
     Wrapper around zlib's z_stream structure which provides convenient
     compression functionality.
     """
-    def __init__(self, space, level=rzlib.Z_DEFAULT_COMPRESSION,
-                 method=rzlib.Z_DEFLATED,             # \
-                 wbits=rzlib.MAX_WBITS,               #  \   undocumented
-                 memLevel=rzlib.DEF_MEM_LEVEL,        #  /    parameters
-                 strategy=rzlib.Z_DEFAULT_STRATEGY,   # /
-                 stream=None):
+    def __init__(self, space, stream):
         ZLibObject.__init__(self, space)
-        if stream is None:
-            try:
-                stream = rzlib.deflateInit(level, method, wbits,
-                                                memLevel, strategy)
-            except rzlib.RZlibError as e:
-                raise zlib_error(space, e.msg)
-            except ValueError:
-                raise oefmt(space.w_ValueError, "Invalid initialization option")
         self.stream = stream
         self.register_finalizer(space)
 
@@ -237,8 +224,13 @@
     """
     w_stream = space.allocate_instance(Compress, w_subtype)
     w_stream = space.interp_w(Compress, w_stream)
-    Compress.__init__(w_stream, space, level,
-                      method, wbits, memLevel, strategy)
+    try:
+        stream = rzlib.deflateInit(level, method, wbits, memLevel, strategy)
+    except rzlib.RZlibError as e:
+        raise zlib_error(space, e.msg)
+    except ValueError:
+        raise oefmt(space.w_ValueError, "Invalid initialization option")
+    Compress.__init__(w_stream, space, stream)
     return w_stream
 
 
@@ -259,14 +251,7 @@
     Wrapper around zlib's z_stream structure which provides convenient
     decompression functionality.
     """
-    def __init__(
-        self,
-        space,
-        wbits=rzlib.MAX_WBITS,
-        stream=None,
-        unused_data="",
-        unconsumed_tail="",
-    ):
+    def __init__(self, space, stream, unused_data, unconsumed_tail):
         """
         Initialize a new decompression object.
 
@@ -277,13 +262,6 @@
         """
         ZLibObject.__init__(self, space)
 
-        if stream is None:
-            try:
-                stream = rzlib.inflateInit(wbits)
-            except rzlib.RZlibError as e:
-                raise zlib_error(space, e.msg)
-            except ValueError:
-                raise oefmt(space.w_ValueError, "Invalid initialization option")
         self.stream = stream
         self.unused_data = unused_data
         self.unconsumed_tail = unconsumed_tail
@@ -389,7 +367,13 @@
     """
     w_stream = space.allocate_instance(Decompress, w_subtype)
     w_stream = space.interp_w(Decompress, w_stream)
-    Decompress.__init__(w_stream, space, wbits)
+    try:
+        stream = rzlib.inflateInit(wbits)
+    except rzlib.RZlibError as e:
+        raise zlib_error(space, e.msg)
+    except ValueError:
+        raise oefmt(space.w_ValueError, "Invalid initialization option")
+    Decompress.__init__(w_stream, space, stream, '', '')
     return w_stream
 
 


More information about the pypy-commit mailing list