Commits

Philip Jenvey committed f07a82d

binascii crc32 results now also back to unsigned

Comments (0)

Files changed (2)

pypy/module/binascii/interp_crc32.py

     for c in data:
         crc = crc_32_tab[(crc & 0xff) ^ ord(c)] ^ (crc >> 8)
 
-    crc = ~intmask(rffi.cast(rffi.INT, crc))   # unsigned => 32-bit signed
-    return space.wrap(crc)
+    return space.wrap(crc ^ 0xFFFFFFFF)

pypy/module/binascii/test/test_binascii.py

         for input, initial, expected in [
             (b"", 0, 0),
             (b"", 123, 123),
-            (b"hello", 321, -348147686),
+            (b"hello", 321, 3946819610),
             (b"world", -2147483648, 32803080),
             (b"world", 2147483647, 942244330),
-            (b'a', 10000, -184504832),
+            (b'a', 10000, 4110462464),
             (b'b', 10000, 1812594618),
             (b'c', 10000, 453955372),
-            (b'd', 10000, -2056627569),
-            (b'e', 10000, -227710439),
+            (b'd', 10000, 2238339727),
+            (b'e', 10000, 4067256857),
             (b'f', 10000, 1801730979),
             (b'g', 10000, 476252981),
-            (b'h', 10000, -1931733340),
-            (b'i', 10000, -69523918),
+            (b'h', 10000, 2363233956),
+            (b'i', 10000, 4225443378),
             (b'j', 10000, 1657960328),
             (b'k', 10000, 366298910),
-            (b'l', 10000, -1951280451),
-            (b'm', 10000, -55123413),
+            (b'l', 10000, 2343686845),
+            (b'm', 10000, 4239843883),
             (b'n', 10000, 1707062161),
             (b'o', 10000, 314082055),
-            (b'p', 10000, -1615819022),
-            (b'q', 10000, -390611356),
+            (b'p', 10000, 2679148274),
+            (b'q', 10000, 3904355940),
             (b'r', 10000, 1908338654),
             (b's', 10000, 112844616),
-            (b't', 10000, -1730327829),
-            (b'u', 10000, -270894467),
+            (b't', 10000, 2564639467),
+            (b'u', 10000, 4024072829),
             (b'v', 10000, 1993550791),
             (b'w', 10000, 30677841),
-            (b'x', 10000, -1855256896),
-            (b'y', 10000, -429115818),
+            (b'x', 10000, 2439710400),
+            (b'y', 10000, 3865851478),
             (b'z', 10000, 2137352172),
-            (b'foo', 99999999999999999999999999, -1932704816),
+            (b'foo', 99999999999999999999999999, 2362262480),
             (b'bar', -99999999999999999999999999, 2000545409),
             ]:
             assert self.binascii.crc32(input, initial) == expected