[pypy-svn] r62145 - pypy/branch/spy-graphic/pypy/lang/smalltalk

witulski at codespeak.net witulski at codespeak.net
Wed Feb 25 15:15:08 CET 2009


Author: witulski
Date: Wed Feb 25 15:15:06 2009
New Revision: 62145

Modified:
   pypy/branch/spy-graphic/pypy/lang/smalltalk/constants.py
   pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py
Log:
(witulski, cfbolz): properly use ovfcheck_lshift for overflow detection of left-shifting.


Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/constants.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/constants.py	(original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/constants.py	Wed Feb 25 15:15:06 2009
@@ -1,5 +1,3 @@
-from pypy.rlib.rarithmetic import LONG_BIT
-
 # ___________________________________________________________________________
 # Slot Names
 
@@ -131,5 +129,6 @@
     "smalltalkdict" : SO_SMALLTALK,
 }
 
+LONG_BIT = 32
 TAGGED_MAXINT = 2 ** (LONG_BIT - 2) - 1
 TAGGED_MININT = -2 ** (LONG_BIT - 2)

Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py	Wed Feb 25 15:15:06 2009
@@ -200,22 +200,12 @@
 
     # left shift, must fail if we lose bits beyond 32
     if argument > 0:
-        shifted = receiver << argument
-
-        # Make sure we respect our bitlimits set by TAGGED_XXXINT.
-        if shifted < 0:
-            # If negative, check if there are no bits unset outside the MAXINT
-            # region
-            if constants.TAGGED_MININT ^ shifted > constants.TAGGED_MAXINT:
-                raise PrimitiveFailedError()
-        else:
-            # If possitive, check if there are no bits set outside the MAXINT
-            # region
-            if shifted & constants.TAGGED_MAXINT != shifted:
-                raise PrimitiveFailedError()
-        
+        try:
+            shifted = rarithmetic.ovfcheck_lshift(receiver, argument)
+        except OverflowError:
+            raise PrimitiveFailedError()
         return interp.space.wrap_int(shifted)
-            
+
     # right shift, ok to lose bits
     else:
         return interp.space.wrap_int(receiver >> -argument)



More information about the Pypy-commit mailing list