Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r89192:c6bab3382b8a
Date: 2016-12-20 10:10 +0100
http://bitbucket.org/pypy/pypy/changeset/c6bab3382b8a/

Log:    Fix the calls to crc32/adler32

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
@@ -5,6 +5,7 @@
 from pypy.interpreter.error import OperationError, oefmt
 from rpython.rlib.rarithmetic import intmask, r_uint
 from rpython.rlib.objectmodel import keepalive_until_here
+from rpython.rtyper.lltypesystem import rffi
 
 from rpython.rlib import rzlib
 
@@ -15,9 +16,7 @@
 else:
     # 64-bit platforms
     def unsigned_to_signed_32bit(x):
-        # assumes that 'x' is in range(0, 2**32) to start with
-        SIGN_EXTEND2 = 1 << 31
-        return intmask((x ^ SIGN_EXTEND2) - SIGN_EXTEND2)
+        return intmask(rffi.cast(rffi.INT, x))
 
 
 @unwrap_spec(string='bufferstr', start='truncatedint_w')
diff --git a/pypy/module/zlib/test/test_zlib.py 
b/pypy/module/zlib/test/test_zlib.py
--- a/pypy/module/zlib/test/test_zlib.py
+++ b/pypy/module/zlib/test/test_zlib.py
@@ -2,6 +2,7 @@
 Tests for the zlib module.
 """
 
+import sys
 try:
     import zlib
 except ImportError:
@@ -16,6 +17,10 @@
     assert interp_zlib.unsigned_to_signed_32bit(123) == 123
     assert interp_zlib.unsigned_to_signed_32bit(2**31) == -2**31
     assert interp_zlib.unsigned_to_signed_32bit(2**32-1) == -1
+    if sys.maxint > 2**32:
+        from rpython.rlib.rarithmetic import r_uint
+        assert interp_zlib.unsigned_to_signed_32bit(r_uint(sys.maxint)) == -1
+        assert interp_zlib.unsigned_to_signed_32bit(r_uint(sys.maxint+1)) == 0
 
 
 class AppTestZlib(object):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to