Author: Tim Felgentreff <[email protected]>
Branch: 
Changeset: r262:96cf1b58e649
Date: 2013-04-12 15:30 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/96cf1b58e649/

Log:    add overflow checking to LPI lshift (because debug build assertion
        failed)

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -262,12 +262,15 @@
         return "W_LargePositiveInteger1Word(%d)" % r_uint(self.value)
 
     def lshift(self, space, shift):
-        from rpython.rlib.rarithmetic import intmask, r_uint
+        from rpython.rlib.rarithmetic import ovfcheck, intmask, r_uint
         # shift > 0, therefore the highest bit of upperbound is not set,
         # i.e. upperbound is positive
         upperbound = intmask(r_uint(-1) >> shift)
         if 0 <= self.value <= upperbound:
-            shifted = intmask(self.value << shift)
+            try:
+                shifted = intmask(ovfcheck(self.value << shift))
+            except OverflowError:
+                raise error.PrimitiveFailedError()
             return space.wrap_positive_32bit_int(shifted)
         else:
             raise error.PrimitiveFailedError()
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -219,8 +219,7 @@
 # #bitShift: -- return the shifted value
 @expose_primitive(BIT_SHIFT, unwrap_spec=[object, int])
 def func(interp, s_frame, receiver, argument):
-    # Failing! Use ovfcheck_lfshift
-    # (http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html#integer-types)
+    # overflow-checking done in lshift implementations
     if argument > 0:
         return receiver.lshift(interp.space, argument)
     else:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to