Author: Alex Gaynor <[email protected]>
Branch: erase-raw-mem
Changeset: r53399:9391e8143f32
Date: 2012-03-12 17:33 -0700
http://bitbucket.org/pypy/pypy/changeset/9391e8143f32/

Log:    (arigato, alex, fijal) exception catching magic

diff --git a/pypy/rlib/rerased_raw.py b/pypy/rlib/rerased_raw.py
--- a/pypy/rlib/rerased_raw.py
+++ b/pypy/rlib/rerased_raw.py
@@ -79,25 +79,30 @@
 
     def rtyper_new(self, hop):
         [v_arg] = hop.inputargs(lltype.Signed)
+        hop.exception_cannot_occur()
         return hop.gendirectcall(self.ll_new, v_arg)
 
     def rtype_method_getint(self, hop):
         [v_arr, v_idx] = hop.inputargs(self, lltype.Signed)
+        hop.exception_cannot_occur()
         return hop.genop("getarrayitem", [v_arr, v_idx], 
resulttype=lltype.Signed)
 
     def rtype_method_setint(self, hop):
         [v_arr, v_idx, v_value] = hop.inputargs(self, lltype.Signed, 
lltype.Signed)
+        hop.exception_cannot_occur()
         hop.genop("setarrayitem", [v_arr, v_idx, v_value])
 
     def rtype_method_getinstance(self, hop):
         v_arr = hop.inputarg(self, arg=0)
         v_idx = hop.inputarg(lltype.Signed, arg=1)
+        hop.exception_cannot_occur()
         v_result = hop.genop("getarrayitem", [v_arr, v_idx], 
resulttype=lltype.Signed)
         v_addr = hop.genop("cast_int_to_adr", [v_result], 
resulttype=llmemory.Address)
         return hop.genop("cast_adr_to_ptr", [v_addr], 
resulttype=hop.r_result.lowleveltype)
 
     def rtype_method_setinstance(self, hop):
         [v_arr, v_idx, v_instance] = hop.inputargs(self, lltype.Signed, 
hop.args_r[2])
+        hop.exception_cannot_occur()
         v_addr = hop.genop("cast_ptr_to_adr", [v_instance], 
resulttype=llmemory.Address)
         v_result = hop.genop("cast_adr_to_int", [v_addr, 
hop.inputconst(lltype.Void, "symbolic")], resulttype=lltype.Signed)
         hop.genop("setarrayitem", [v_arr, v_idx, v_result])
diff --git a/pypy/rlib/test/test_rerased_raw.py 
b/pypy/rlib/test/test_rerased_raw.py
--- a/pypy/rlib/test/test_rerased_raw.py
+++ b/pypy/rlib/test/test_rerased_raw.py
@@ -46,3 +46,22 @@
 
         res = self.interpret(f, [27])
         assert res == 27
+
+    def test_exception_catching(self):
+        class A(object):
+            def __init__(self, v):
+                self.v = v
+
+        def f(x):
+            try:
+                storage = rerased_raw.UntypedStorage(2)
+                storage.setint(0, x)
+                value1 = storage.getint(0)
+                storage.setinstance(1, A(x))
+                value2 = storage.getinstance(1, A)
+                return value1 + value2.v
+            except Exception:
+                return 50000
+
+        res = self.interpret(f, [4])
+        assert res == 8
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to