* 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
This commit is contained in:
nobu 2009-07-05 05:04:41 +00:00
Родитель fd4d1dde2f
Коммит b35d1e714c
4 изменённых файлов: 39 добавлений и 19 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Sun Jul 5 14:04:36 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* vm_method.c (rb_add_method, remove_method, rb_undef): fixed

Просмотреть файл

@ -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

Просмотреть файл

@ -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)
{

Просмотреть файл

@ -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)