[pypy-commit] pypy py3k: reapply py3k's special casing of int() results and fix buffer handling

pjenvey noreply at buildbot.pypy.org
Thu Dec 19 00:48:56 CET 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r68476:225823af4c47
Date: 2013-12-18 15:45 -0800
http://bitbucket.org/pypy/pypy/changeset/225823af4c47/

Log:	reapply py3k's special casing of int() results and fix buffer
	handling

diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py
--- a/pypy/objspace/std/longtype.py
+++ b/pypy/objspace/std/longtype.py
@@ -29,12 +29,10 @@
         elif type(w_value) is W_LongObject:
             return newbigint(space, w_longtype, w_value.num)
         elif space.lookup(w_value, '__int__') is not None:
-            w_obj = space.int(w_value)
-            return newbigint(space, w_longtype, space.bigint_w(w_obj))
+            return _from_intlike(space, w_longtype, w_value)
         elif space.lookup(w_value, '__trunc__') is not None:
             w_obj = space.trunc(w_value)
-            w_obj = space.int(w_obj)
-            return newbigint(space, w_longtype, space.bigint_w(w_obj))
+            return _from_intlike(space, w_longtype, w_obj)
         elif space.isinstance_w(w_value, space.w_unicode):
             from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
             return string_to_w_long(space, w_longtype,
@@ -54,7 +52,8 @@
                     w_value)
             else:
                 buf = space.interp_w(Buffer, w_buffer)
-                return string_to_w_long(space, w_longtype, buf.as_str())
+                return string_to_w_long(space, w_longtype,
+                                        buf.as_str().decode('latin-1'))
     else:
         try:
             base = space.int_w(w_base)
@@ -77,6 +76,13 @@
         return string_to_w_long(space, w_longtype, s, base)
 
 
+def _from_intlike(space, w_longtype, w_intlike):
+    w_obj = space.int(w_intlike)
+    if space.is_w(w_longtype, space.w_int):
+        return w_obj
+    return newbigint(space, w_longtype, space.bigint_w(w_obj))
+
+
 def string_to_w_long(space, w_longtype, s, base=10):
     try:
         bigint = rbigint.fromstr(s, base)


More information about the pypy-commit mailing list