Author: Philip Jenvey <[email protected]>
Branch: 
Changeset: r59354:2bef84196680
Date: 2012-12-06 17:52 -0800
http://bitbucket.org/pypy/pypy/changeset/2bef84196680/

Log:    fix frombytes on empty strings (transplanted from
        b1a4f4d62d781879b56bf63cd0da4628ee0518ac)

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -273,6 +273,8 @@
     def frombytes(s, byteorder, signed):
         if byteorder not in ('big', 'little'):
             raise InvalidEndiannessError()
+        if not s:
+            return NULLRBIGINT
 
         if byteorder != BYTEORDER:
             msb = ord(s[0])
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
@@ -771,6 +771,8 @@
         assert res == -42.0
 
     def test_frombytes(self):
+        bigint = rbigint.frombytes('', byteorder='big', signed=True)
+        assert bigint.tolong() == 0
         s = "\xFF\x12\x34\x56"
         bigint = rbigint.frombytes(s, byteorder="big", signed=False)
         assert bigint.tolong() == 0xFF123456
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to