[pypy-svn] pypy default: have the llbackend raise on ValueError on bad shift counts
hakanardo
commits-noreply at bitbucket.org
Mon Apr 25 12:23:29 CEST 2011
Author: Hakan Ardo <hakan at debian.org>
Branch:
Changeset: r43567:4c695a1b8a86
Date: 2011-04-25 12:21 +0200
http://bitbucket.org/pypy/pypy/changeset/4c695a1b8a86/
Log: have the llbackend raise on ValueError on bad shift counts
diff --git a/pypy/jit/metainterp/blackhole.py b/pypy/jit/metainterp/blackhole.py
--- a/pypy/jit/metainterp/blackhole.py
+++ b/pypy/jit/metainterp/blackhole.py
@@ -238,6 +238,10 @@
interp.cleanup_registers()
self.blackholeinterps.append(interp)
+def check_shift_count(b):
+ if not we_are_translated():
+ if b < 0 or b >= LONG_BIT:
+ raise ValueError("Shift count, %d, not in valid range, 0 .. %d." % (b, LONG_BIT-1))
class BlackholeInterpreter(object):
@@ -420,14 +424,17 @@
@arguments("i", "i", returns="i")
def bhimpl_int_rshift(a, b):
+ check_shift_count(b)
return a >> b
@arguments("i", "i", returns="i")
def bhimpl_int_lshift(a, b):
+ check_shift_count(b)
return intmask(a << b)
@arguments("i", "i", returns="i")
def bhimpl_uint_rshift(a, b):
+ check_shift_count(b)
c = r_uint(a) >> r_uint(b)
return intmask(c)
diff --git a/pypy/jit/metainterp/test/test_blackhole.py b/pypy/jit/metainterp/test/test_blackhole.py
--- a/pypy/jit/metainterp/test/test_blackhole.py
+++ b/pypy/jit/metainterp/test/test_blackhole.py
@@ -217,3 +217,16 @@
for x in range(1, 8)])
builder = pyjitpl._warmrunnerdesc.metainterp_sd.blackholeinterpbuilder
assert builder.num_interpreters == 2
+
+def test_bad_shift():
+ py.test.raises(ValueError, BlackholeInterpreter.bhimpl_int_lshift.im_func, 7, 100)
+ py.test.raises(ValueError, BlackholeInterpreter.bhimpl_int_rshift.im_func, 7, 100)
+ py.test.raises(ValueError, BlackholeInterpreter.bhimpl_uint_rshift.im_func, 7, 100)
+ py.test.raises(ValueError, BlackholeInterpreter.bhimpl_int_lshift.im_func, 7, -1)
+ py.test.raises(ValueError, BlackholeInterpreter.bhimpl_int_rshift.im_func, 7, -1)
+ py.test.raises(ValueError, BlackholeInterpreter.bhimpl_uint_rshift.im_func, 7, -1)
+
+ assert BlackholeInterpreter.bhimpl_int_lshift.im_func(100, 3) == 100<<3
+ assert BlackholeInterpreter.bhimpl_int_rshift.im_func(100, 3) == 100>>3
+ assert BlackholeInterpreter.bhimpl_uint_rshift.im_func(100, 3) == 100>>3
+
More information about the Pypy-commit
mailing list