Author: Antonio Cuni <[email protected]>
Branch: py3k
Changeset: r53880:01ce09ec95e6
Date: 2012-03-21 23:15 +0000
http://bitbucket.org/pypy/pypy/changeset/01ce09ec95e6/
Log: on 32bits, the accum variable might overflow to a long; make sure to
cast back so a signed int before passing it to _store_digits
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -224,11 +224,11 @@
accum |= c
accumbits += 8
if accumbits >= SHIFT:
- digits.append(_store_digit(accum & MASK))
+ digits.append(_store_digit(intmask(accum & MASK)))
accum >>= SHIFT
accumbits -= SHIFT
if accumbits:
- digits.append(_store_digit(accum))
+ digits.append(_store_digit(intmask(accum)))
return rbigint(digits[:], 1)
@jit.elidable
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -692,3 +692,8 @@
res = interpret(fn, [])
assert res == -42.0
+
+ def test_frombytes(self):
+ s = "\xFF\x12\x34\x56"
+ bigint = rbigint.frombytes(s)
+ assert bigint.tolong() == 0xFF123456
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit