[pypy-commit] pypy win64-stage1: weird special casing in std-objspace.py::wrap. This function is not even

ctismer noreply at buildbot.pypy.org
Sun Dec 4 05:39:38 CET 2011

Author: Christian Tismer <tismer at stackless.com>
Branch: win64-stage1
Changeset: r50104:5b5913c63621
Date: 2011-12-04 05:39 +0100

Log:	weird special casing in std-objspace.py::wrap. This function is not
	even RPython, and I had to inline is_valid_int. Why is this so
	special? Is that still necessary, or just not changed?

diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -9,7 +9,7 @@
 from pypy.objspace.descroperation import DescrOperation, raiseattrerror
 from pypy.rlib.objectmodel import instantiate, r_dict, specialize, is_annotation_constant
 from pypy.rlib.debug import make_sure_not_resized
-from pypy.rlib.rarithmetic import base_int, widen, is_valid_int
+from pypy.rlib.rarithmetic import base_int, widen, maxint
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib import jit
@@ -160,11 +160,15 @@
         if isinstance(x, OperationError):
             raise TypeError, ("attempt to wrap already wrapped exception: %s"%
-        if is_valid_int(x):
+        if isinstance(x, int):
             if isinstance(x, bool):
                 return self.newbool(x)
                 return self.newint(x)
+        # this is an inlined 'is_valid_int' which cannot be used
+        # due to the special annotation nature of 'wrap'.
+        if isinstance(x, long) and (-maxint - 1 <= x <= maxint):
+            return self.newint(x)
         if isinstance(x, str):
             return wrapstr(self, x)
         if isinstance(x, unicode):

More information about the pypy-commit mailing list