mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
fd4d1dde2f
commit
b35d1e714c
4 changed files with 39 additions and 19 deletions
|
@ -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>
|
Sun Jul 5 08:14:38 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* vm_method.c (rb_add_method, remove_method, rb_undef): fixed
|
* vm_method.c (rb_add_method, remove_method, rb_undef): fixed
|
||||||
|
|
|
@ -181,4 +181,9 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
||||||
def test_invalid_proc
|
def test_invalid_proc
|
||||||
assert_raise(TypeError) { set_trace_func(1) }
|
assert_raise(TypeError) { set_trace_func(1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_raise_in_trace
|
||||||
|
set_trace_func proc {raise rescue nil}
|
||||||
|
assert_equal(42, (raise rescue 42), '[ruby-core:24118]')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
26
thread.c
26
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);
|
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
|
void
|
||||||
rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
|
rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
|
||||||
{
|
{
|
||||||
|
|
22
vm_core.h
22
vm_core.h
|
@ -639,30 +639,14 @@ void rb_threadptr_execute_interrupts(rb_thread_t *);
|
||||||
RUBY_VM_CHECK_INTS_TH(GET_THREAD())
|
RUBY_VM_CHECK_INTS_TH(GET_THREAD())
|
||||||
|
|
||||||
/* tracer */
|
/* tracer */
|
||||||
static inline void
|
void
|
||||||
exec_event_hooks(rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
|
rb_threadptr_exec_event_hooks(rb_thread_t *th, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \
|
#define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \
|
||||||
rb_event_flag_t wait_event__ = th->event_flags; \
|
rb_event_flag_t wait_event__ = th->event_flags; \
|
||||||
if (UNLIKELY(wait_event__)) { \
|
if (UNLIKELY(wait_event__)) { \
|
||||||
if (wait_event__ & (flag | RUBY_EVENT_VM)) { \
|
if (wait_event__ & (flag | RUBY_EVENT_VM)) { \
|
||||||
VALUE self__ = (self), klass__ = (klass); \
|
rb_threadptr_exec_event_hooks(th, flag, self, id, 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__); \
|
|
||||||
} \
|
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue