Author: Antonio Cuni <[email protected]>
Branch: hpy
Changeset: r98114:3a384fd65d2e
Date: 2019-11-18 15:27 +0100
http://bitbucket.org/pypy/pypy/changeset/3a384fd65d2e/
Log: (antocuni, arigo): add a passing test which we needed to convince
ourselves that you can raise exceptions from within llhelper()ed
functions
diff --git a/rpython/translator/test/test_exceptiontransform.py
b/rpython/translator/test/test_exceptiontransform.py
--- a/rpython/translator/test/test_exceptiontransform.py
+++ b/rpython/translator/test/test_exceptiontransform.py
@@ -266,3 +266,26 @@
f = self.compile(foo, [])
res = f()
assert res == 42
+
+ def test_llhelper_can_raise(self):
+ from rpython.rtyper.lltypesystem import lltype
+ from rpython.rtyper.annlowlevel import llhelper
+
+ def fn(a, b):
+ if b == 0:
+ raise ZeroDivisionError
+ return a/b
+
+ FN = lltype.Ptr(lltype.FuncType([lltype.Signed, lltype.Signed],
lltype.Signed))
+ def h(a, b):
+ fnptr = llhelper(FN, fn)
+ try:
+ return fnptr(a, b)
+ except ZeroDivisionError:
+ return -a
+
+ compiled_h = self.compile(h, [int, int])
+ res = compiled_h(39, 3)
+ assert res == 13
+ res = compiled_h(39, 0)
+ assert res == -39
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit