From b35d1e714c1df44b5346e35a6dc519da5e8de4d5 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 5 Jul 2009 05:04:41 +0000 Subject: [PATCH] * thread.c (rb_threadptr_exec_event_hooks): new function to execute event hooks, with preserving errinfo. [ruby-core:24118] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_settracefunc.rb | 5 +++++ thread.c | 26 ++++++++++++++++++++++++++ vm_core.h | 22 +++------------------- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index b28857e32a..aec6eb1c87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Jul 5 14:04:36 2009 Nobuyoshi Nakada + + * 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 * vm_method.c (rb_add_method, remove_method, rb_undef): fixed diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index a446969f38..5898ce488d 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -181,4 +181,9 @@ class TestSetTraceFunc < Test::Unit::TestCase 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 diff --git a/thread.c b/thread.c index 63706c9800..c6f9cea24f 100644 --- a/thread.c +++ b/thread.c @@ -3528,6 +3528,32 @@ set_threads_event_flags(int flag) 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) { diff --git a/vm_core.h b/vm_core.h index 43784803db..8019e63a27 100644 --- a/vm_core.h +++ b/vm_core.h @@ -639,30 +639,14 @@ void rb_threadptr_execute_interrupts(rb_thread_t *); 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)