[前][次][番号順一覧][スレッド一覧]

ruby-changes:12268

From: nobu <ko1@a...>
Date: Sun, 5 Jul 2009 14:05:01 +0900 (JST)
Subject: [ruby-changes:12268] Ruby:r23959 (trunk): * thread.c (rb_threadptr_exec_event_hooks): new function to

nobu	2009-07-05 14:04:41 +0900 (Sun, 05 Jul 2009)

  New Revision: 23959

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23959

  Log:
    * thread.c (rb_threadptr_exec_event_hooks): new function to
      execute event hooks, with preserving errinfo.  [ruby-core:24118]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_settracefunc.rb
    trunk/thread.c
    trunk/vm_core.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23958)
+++ ChangeLog	(revision 23959)
@@ -1,3 +1,8 @@
+Sun Jul  5 14:04:36 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* thread.c (rb_threadptr_exec_event_hooks): new function to
+	  execute event hooks, with preserving errinfo.  [ruby-core:24118]
+
 Sun Jul  5 08:14:38 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_method.c (rb_add_method, remove_method, rb_undef): fixed
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 23958)
+++ vm_core.h	(revision 23959)
@@ -639,30 +639,14 @@
   RUBY_VM_CHECK_INTS_TH(GET_THREAD())
 
 /* tracer */
-static inline void
-exec_event_hooks(rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
-{
-    if (self == rb_mRubyVMFrozenCore) return;
-    while (hook) {
-	if (flag & hook->flag) {
-	    (*hook->func)(flag, hook->data, self, id, klass);
-	}
-	hook = hook->next;
-    }
-}
+void
+rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass);
 
 #define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \
     rb_event_flag_t wait_event__ = th->event_flags; \
     if (UNLIKELY(wait_event__)) { \
 	if (wait_event__ & (flag | RUBY_EVENT_VM)) { \
-	    VALUE self__ = (self), klass__ = (klass); \
-	    ID id__ = (id); \
-	    if (wait_event__ & flag) { \
-		exec_event_hooks(th->event_hooks, flag, self__, id__, klass__); \
-	    } \
-	    if (wait_event__ & RUBY_EVENT_VM) { \
-		exec_event_hooks(th->vm->event_hooks, flag, self__, id__, klass__); \
-	    } \
+	    rb_threadptr_exec_event_hooks(th, flag, self, id, klass); \
 	} \
     } \
 } while (0)
Index: thread.c
===================================================================
--- thread.c	(revision 23958)
+++ thread.c	(revision 23959)
@@ -3528,7 +3528,33 @@
     st_foreach(GET_VM()->living_threads, set_threads_event_flags_i, (st_data_t) flag);
 }
 
+static inline void
+exec_event_hooks(const rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
+{
+    for (; hook; hook = hook->next) {
+	if (flag & hook->flag) {
+	    (*hook->func)(flag, hook->data, self, id, klass);
+	}
+    }
+}
+
 void
+rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
+{
+    const VALUE errinfo = th->errinfo;
+    const rb_event_flag_t wait_event = th->event_flags;
+
+    if (self == rb_mRubyVMFrozenCore) return;
+    if (wait_event & flag) {
+	exec_event_hooks(th->event_hooks, flag, self, id, klass);
+    }
+    if (wait_event & RUBY_EVENT_VM) {
+	exec_event_hooks(th->vm->event_hooks, flag, self, id, klass);
+    }
+    th->errinfo = errinfo;
+}
+
+void
 rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
 {
     rb_event_hook_t *hook = alloc_event_hook(func, events, data);
Index: test/ruby/test_settracefunc.rb
===================================================================
--- test/ruby/test_settracefunc.rb	(revision 23958)
+++ test/ruby/test_settracefunc.rb	(revision 23959)
@@ -181,4 +181,9 @@
   def test_invalid_proc
     assert_raise(TypeError) { set_trace_func(1) }
   end
+
+  def test_raise_in_trace
+    set_trace_func proc {raise rescue nil}
+    assert_equal(42, (raise rescue 42), '[ruby-core:24118]')
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]