[pypy-commit] pypy default: Use a real exception instead of an assertion in LLFrame.op_debug_assert()

rlamy noreply at buildbot.pypy.org
Tue Nov 3 12:44:00 EST 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: 
Changeset: r80519:46cb647a4410
Date: 2015-11-03 17:43 +0000
http://bitbucket.org/pypy/pypy/changeset/46cb647a4410/

Log:	Use a real exception instead of an assertion in
	LLFrame.op_debug_assert()

diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -41,6 +41,10 @@
     def __str__(self):
         return ': '.join([str(x) for x in self.args])
 
+class LLAssertFailure(Exception):
+    pass
+
+
 def type_name(etype):
     return ''.join(etype.name.chars)
 
@@ -508,7 +512,8 @@
         track(*ll_objects)
 
     def op_debug_assert(self, x, msg):
-        assert x, msg
+        if not x:
+            raise LLAssertFailure(msg)
 
     def op_debug_fatalerror(self, ll_msg, ll_exc=None):
         msg = ''.join(ll_msg.chars)
diff --git a/rpython/rtyper/test/test_rlist.py b/rpython/rtyper/test/test_rlist.py
--- a/rpython/rtyper/test/test_rlist.py
+++ b/rpython/rtyper/test/test_rlist.py
@@ -5,7 +5,7 @@
 
 from rpython.rlib.debug import ll_assert
 from rpython.rtyper.error import TyperError
-from rpython.rtyper.llinterp import LLException
+from rpython.rtyper.llinterp import LLException, LLAssertFailure
 from rpython.rtyper.lltypesystem import rlist as ll_rlist
 from rpython.rtyper.lltypesystem.rlist import ListRepr, FixedSizeListRepr, ll_newlist, ll_fixed_newlist
 from rpython.rtyper.rint import signed_repr
@@ -1182,7 +1182,8 @@
 
         res = self.interpret(f, [0])
         assert res == 1
-        py.test.raises(AssertionError, self.interpret, f, [1])
+        with py.test.raises(LLAssertFailure):
+            self.interpret(f, [1])
 
         def f(x):
             l = [1]
@@ -1227,7 +1228,8 @@
 
         res = self.interpret(f, [0])
         assert res == 1
-        py.test.raises(AssertionError, self.interpret, f, [1])
+        with py.test.raises(LLAssertFailure):
+            self.interpret(f, [1])
 
         def f(x):
             l = [1]
@@ -1264,7 +1266,8 @@
 
         res = self.interpret(f, [0])
         assert res == 1
-        py.test.raises(AssertionError, self.interpret, f, [1])
+        with py.test.raises(LLAssertFailure):
+            self.interpret(f, [1])
 
     def test_charlist_extension_1(self):
         def f(n):
diff --git a/rpython/rtyper/test/test_rstr.py b/rpython/rtyper/test/test_rstr.py
--- a/rpython/rtyper/test/test_rstr.py
+++ b/rpython/rtyper/test/test_rstr.py
@@ -10,6 +10,7 @@
 from rpython.rtyper.rtyper import TyperError
 from rpython.rtyper.test.tool import BaseRtypingTest
 from rpython.rtyper.annlowlevel import llstr, hlstr
+from rpython.rtyper.llinterp import LLAssertFailure
 
 
 def test_parse_fmt():
@@ -979,12 +980,8 @@
 
         res = self.interpret(f, [0])
         assert res == 'z'
-        try:
-            self.interpret_raises(IndexError, f, [1])
-        except (AssertionError,), e:
-            pass
-        else:
-            assert False
+        with py.test.raises(LLAssertFailure):
+            self.interpret(f, [1])
 
         def f(x):
             s = const("z")
@@ -1021,12 +1018,8 @@
 
         res = self.interpret(f, [0])
         assert res == 'z'
-        try:
-            self.interpret_raises(IndexError, f, [1])
-        except (AssertionError,), e:
-            pass
-        else:
-            assert False
+        with py.test.raises(LLAssertFailure):
+            self.interpret(f, [1])
 
     def test_fold_concat(self):
         const = self.const


More information about the pypy-commit mailing list