Forum: Ruby-dev Fwd: nobu:r38293 (trunk): vm_trace.c: exceptions in event hooks

Posted by SASADA Koichi (Guest)
on 2012-12-10 19:43
(Received via mailing list)
$B$3$l!$:#99$NBg$-$J;EMMJQ99$K8+$($k$N$G$9$,!$$$$$$N$G$7$g$&$+!%(B


-------- Original Message --------
Subject: [ruby-changes:26236] nobu:r38293 (trunk): vm_trace.c:
exceptions in event hooks
Date: Mon, 10 Dec 2012 15:25:22 +0900 (JST)
From: nobu <ko1@atdot.net>
Reply-To: ruby-changes@quickml.atdot.net
To: ruby-changes@quickml.atdot.net

nobu  2012-12-10 15:23:44 +0900 (Mon, 10 Dec 2012)

  New Revision: 38293

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=r...

  Log:
    vm_trace.c: exceptions in event hooks

    * vm_trace.c (rb_threadptr_exec_event_hooks): exceptions in event
      hooks should not propagate outside.

  Modified files:
    trunk/ChangeLog
    trunk/KNOWNBUGS.rb
    trunk/test/ruby/test_settracefunc.rb
    trunk/vm_trace.c

Index: ChangeLog
===================================================================
--- ChangeLog  (revision 38292)
+++ ChangeLog  (revision 38293)
@@ -1,3 +1,8 @@
+Mon Dec 10 15:23:35 2012  Nobuyoshi Nakada  <nobu@ruby-lang.org>
+
+  * vm_trace.c (rb_threadptr_exec_event_hooks): exceptions in event
+    hooks should not propagate outside.
+
 Mon Dec 10 15:11:06 2012  Nobuyoshi Nakada  <nobu@ruby-lang.org>

   * compile.c (iseq_compile_each): count flip-flop state in local iseq
Index: KNOWNBUGS.rb
===================================================================
--- KNOWNBUGS.rb  (revision 38292)
+++ KNOWNBUGS.rb  (revision 38293)
@@ -3,5 +3,3 @@
 # So all tests will cause failure.
 #

-assert_equal('ok', "TracePoint.new(:line) {raise}.enable {\n 
1\n}\n'ok'")
-assert_finish(3, 'def m; end; TracePoint.new(:return) {raise}.enable 
{m}')
Index: vm_trace.c
===================================================================
--- vm_trace.c  (revision 38292)
+++ vm_trace.c  (revision 38293)
@@ -286,14 +286,14 @@
     if (th->trace_running == 0 &&
   targ->self != rb_mRubyVMFrozenCore /* skip special methods. TODO:
remove it. */) {
   const int vm_tracing = th->vm->trace_running;
+  const VALUE errinfo = th->errinfo;
+  const int outer_state = th->state;
   int state = 0;
-  int outer_state = th->state;
   th->state = 0;

   th->vm->trace_running = 1;
   th->trace_running = 1;
   {
-      const VALUE errinfo = th->errinfo;
       rb_hook_list_t *list;

       /* thread local traces */
@@ -309,15 +309,11 @@
     state = exec_hooks(th, list, targ, !vm_tracing);
     if (state) goto terminate;
       }
-      th->errinfo = errinfo;
   }
       terminate:
+  th->errinfo = errinfo;
   th->trace_running = 0;
   th->vm->trace_running = vm_tracing;
-
-  if (state) {
-      TH_JUMP_TAG(th, state);
-  }
   th->state = outer_state;
     }
 }
Index: test/ruby/test_settracefunc.rb
===================================================================
--- test/ruby/test_settracefunc.rb  (revision 38292)
+++ test/ruby/test_settracefunc.rb  (revision 38293)
@@ -798,4 +798,18 @@
       end
     }
   end
+
+  def test_tracepoint_exception_at_line
+    assert_nothing_raised do
+      TracePoint.new(:line) {raise}.enable {
+        1
+      }
+    end
+  end
+
+  def test_tracepoint_exception_at_return
+    assert_nothing_raised(Timeout::Error, 'infinite trace') do
+      assert_normal_exit('def m; end; TracePoint.new(:return)
{raise}.enable {m}', '', timeout: 3)
+    end
+  end
 end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.