Author: Maciej Fijalkowski <[email protected]>
Branch: jit-applevel-hook
Changeset: r44623:b5d05e0590a6
Date: 2011-06-01 16:23 +0200
http://bitbucket.org/pypy/pypy/changeset/b5d05e0590a6/

Log:    A fix for what happens if you raise the exception in jithook

diff --git a/pypy/module/pypyjit/interp_jit.py 
b/pypy/module/pypyjit/interp_jit.py
--- a/pypy/module/pypyjit/interp_jit.py
+++ b/pypy/module/pypyjit/interp_jit.py
@@ -62,13 +62,16 @@
             list_w = [space.wrap(logger.repr_of_resop(memo, op))
                       for op in operations]
             pycode = cast_base_ptr_to_instance(PyCode, ll_pycode)
-            space.call_function(cache.w_compile_hook,
-                                space.wrap('main'),
-                                space.wrap(type),
-                                space.newtuple([pycode,
-                                space.wrap(next_instr),
-                                space.wrap(is_being_profiled)]),
-                                space.newlist(list_w))
+            try:
+                space.call_function(cache.w_compile_hook,
+                                    space.wrap('main'),
+                                    space.wrap(type),
+                                    space.newtuple([pycode,
+                                    space.wrap(next_instr),
+                                    space.wrap(is_being_profiled)]),
+                                    space.newlist(list_w))
+            except OperationError, e:
+                e.write_unraisable(space, "jit hook ", cache.w_compile_hook)
 
     def on_compile_bridge(self, logger, orig_looptoken, operations, n):
         space = self.space
@@ -77,11 +80,14 @@
             memo = {}
             list_w = [space.wrap(logger.repr_of_resop(memo, op))
                       for op in operations]
-            space.call_function(cache.w_compile_hook,
-                                space.wrap('main'),
-                                space.wrap('bridge'),
-                                space.wrap(n),
-                                space.newlist(list_w))
+            try:
+                space.call_function(cache.w_compile_hook,
+                                    space.wrap('main'),
+                                    space.wrap('bridge'),
+                                    space.wrap(n),
+                                    space.newlist(list_w))
+            except OperationError, e:
+                e.write_unraisable(space, "jit hook ", cache.w_compile_hook)
 
 pypyjitdriver = PyPyJitDriver(get_printable_location = get_printable_location,
                               get_jitcell_at = get_jitcell_at,
diff --git a/pypy/module/pypyjit/test/test_jit_hook.py 
b/pypy/module/pypyjit/test/test_jit_hook.py
--- a/pypy/module/pypyjit/test/test_jit_hook.py
+++ b/pypy/module/pypyjit/test/test_jit_hook.py
@@ -67,3 +67,19 @@
         pypyjit.set_compile_hook(None)
         self.on_compile()
         assert len(all) == 2
+
+    def test_on_compile_exception(self):
+        import pypyjit, sys, cStringIO
+
+        def hook(*args):
+            1/0
+
+        pypyjit.set_compile_hook(hook)
+        s = cStringIO.StringIO()
+        sys.stderr = s
+        try:
+            self.on_compile()
+        finally:
+            sys.stderr = sys.__stderr__
+        assert 'jit hook' in s.getvalue()
+        assert 'ZeroDivisionError' in s.getvalue()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to