Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r81528:c626616a34fa
Date: 2016-01-03 02:15 +0100
http://bitbucket.org/pypy/pypy/changeset/c626616a34fa/

Log:    Fix _PyLong_FromByteArray() for e205bcf52d2f

diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -5,7 +5,7 @@
 from pypy.objspace.std.longobject import W_LongObject
 from pypy.interpreter.error import OperationError
 from pypy.module.cpyext.intobject import PyInt_AsUnsignedLongMask
-from rpython.rlib.rbigint import rbigint
+from rpython.rlib.rbigint import rbigint, NULLRBIGINT, ONERBIGINT
 from rpython.rlib.rarithmetic import intmask
 
 
@@ -229,25 +229,21 @@
     little_endian = rffi.cast(lltype.Signed, little_endian)
     signed = rffi.cast(lltype.Signed, signed)
 
-    result = rbigint()
-    negative = False
+    # xxx not the most efficient implementation possible, but should work
+    result = NULLRBIGINT
+    c = 0
 
     for i in range(0, n):
         if little_endian:
+            c = intmask(bytes[n - i - 1])
+        else:
             c = intmask(bytes[i])
-        else:
-            c = intmask(bytes[n - i - 1])
-        if i == 0 and signed and c & 0x80:
-            negative = True
-        if negative:
-            c = c ^ 0xFF
         digit = rbigint.fromint(c)
 
         result = result.lshift(8)
         result = result.add(digit)
 
-    if negative:
-        result = result.neg()
+    if signed and c >= 0x80:
+        result = result.sub(ONERBIGINT.lshift(8 * n))
 
     return space.newlong_from_rbigint(result)
-
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to