mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 00:54:01 +02:00
merge revision(s) 46465,46469,46484: [Backport #9961]
* vm.c (rb_vm_rewind_cfp): add new function to rewind specified cfp with invoking RUBY_EVENT_C_RETURN. [Bug #9961] * vm_core.h: ditto. * eval.c (rb_protect): use it. * eval.c (rb_rescue2): ditto. * vm_eval.c (rb_iterate): ditto. * test/ruby/test_settracefunc.rb: add a test. * vm_core.h (rb_name_err_mesg_new): * vm_eval.c (rb_catch_protect): fix same problem of [Bug #9961]. * vm_eval.c (rb_iterate): ditto. * vm_core.h (rb_vm_rewind_cfp): add the prototype declaration. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3ed06c80eb
commit
b10c3b6d51
7 changed files with 100 additions and 17 deletions
24
ChangeLog
24
ChangeLog
|
@ -1,3 +1,27 @@
|
||||||
|
Sun Aug 31 16:59:45 2014 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* vm_eval.c (rb_catch_protect): fix same problem of [Bug #9961].
|
||||||
|
|
||||||
|
* vm_eval.c (rb_iterate): ditto.
|
||||||
|
|
||||||
|
Sun Aug 31 16:59:45 2014 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* vm.c (rb_vm_rewind_cfp): add new function to rewind specified cfp
|
||||||
|
with invoking RUBY_EVENT_C_RETURN.
|
||||||
|
[Bug #9961]
|
||||||
|
|
||||||
|
* vm_core.h: ditto.
|
||||||
|
|
||||||
|
* eval.c (rb_protect): use it.
|
||||||
|
|
||||||
|
* eval.c (rb_rescue2): ditto.
|
||||||
|
|
||||||
|
* vm_eval.c (rb_iterate): ditto.
|
||||||
|
|
||||||
|
* test/ruby/test_settracefunc.rb: add a test.
|
||||||
|
|
||||||
|
* vm_core.h (rb_name_err_mesg_new):
|
||||||
|
|
||||||
Sun Aug 31 16:50:06 2014 Koichi Sasada <ko1@atdot.net>
|
Sun Aug 31 16:50:06 2014 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* compile.c (rb_iseq_compile_node): put start label of block after
|
* compile.c (rb_iseq_compile_node): put start label of block after
|
||||||
|
|
4
eval.c
4
eval.c
|
@ -714,7 +714,7 @@ rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1,
|
||||||
result = (*b_proc) (data1);
|
result = (*b_proc) (data1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
th->cfp = cfp; /* restore */
|
rb_vm_rewind_cfp(th, cfp);
|
||||||
|
|
||||||
if (state == TAG_RAISE) {
|
if (state == TAG_RAISE) {
|
||||||
int handle = FALSE;
|
int handle = FALSE;
|
||||||
|
@ -793,7 +793,7 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int * state)
|
||||||
*state = status;
|
*state = status;
|
||||||
}
|
}
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
th->cfp = cfp;
|
rb_vm_rewind_cfp(th, cfp);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1184,6 +1184,57 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
||||||
assert_equal call_events, return_events.reverse, message
|
assert_equal call_events, return_events.reverse, message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rb_rescue
|
||||||
|
events = []
|
||||||
|
curr_thread = Thread.current
|
||||||
|
TracePoint.new(:b_call, :b_return, :c_call, :c_return){|tp|
|
||||||
|
next if curr_thread != Thread.current
|
||||||
|
events << [tp.event, tp.method_id]
|
||||||
|
}.enable do
|
||||||
|
begin
|
||||||
|
-Numeric.new
|
||||||
|
rescue => e
|
||||||
|
# ignore
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal [
|
||||||
|
[:b_call, :test_rb_rescue],
|
||||||
|
[:c_call, :new],
|
||||||
|
[:c_call, :initialize],
|
||||||
|
[:c_return, :initialize],
|
||||||
|
[:c_return, :new],
|
||||||
|
[:c_call, :-@],
|
||||||
|
[:c_call, :coerce],
|
||||||
|
[:c_call, :to_s],
|
||||||
|
[:c_return, :to_s],
|
||||||
|
[:c_call, :new],
|
||||||
|
[:c_call, :initialize],
|
||||||
|
[:c_return, :initialize],
|
||||||
|
[:c_return, :new],
|
||||||
|
[:c_call, :exception],
|
||||||
|
[:c_return, :exception],
|
||||||
|
[:c_call, :backtrace],
|
||||||
|
[:c_return, :backtrace],
|
||||||
|
[:c_return, :coerce], # don't miss it!
|
||||||
|
[:c_call, :to_s],
|
||||||
|
[:c_return, :to_s],
|
||||||
|
[:c_call, :to_s],
|
||||||
|
[:c_return, :to_s],
|
||||||
|
[:c_call, :new],
|
||||||
|
[:c_call, :initialize],
|
||||||
|
[:c_return, :initialize],
|
||||||
|
[:c_return, :new],
|
||||||
|
[:c_call, :exception],
|
||||||
|
[:c_return, :exception],
|
||||||
|
[:c_call, :backtrace],
|
||||||
|
[:c_return, :backtrace],
|
||||||
|
[:c_return, :-@],
|
||||||
|
[:c_call, :===],
|
||||||
|
[:c_return, :===],
|
||||||
|
[:b_return, :test_rb_rescue]], events
|
||||||
|
end
|
||||||
|
|
||||||
def test_b_call_with_redo
|
def test_b_call_with_redo
|
||||||
assert_consistent_call_return do
|
assert_consistent_call_return do
|
||||||
i = 0
|
i = 0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.0.0"
|
#define RUBY_VERSION "2.0.0"
|
||||||
#define RUBY_RELEASE_DATE "2014-08-31"
|
#define RUBY_RELEASE_DATE "2014-08-31"
|
||||||
#define RUBY_PATCHLEVEL 541
|
#define RUBY_PATCHLEVEL 542
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2014
|
#define RUBY_RELEASE_YEAR 2014
|
||||||
#define RUBY_RELEASE_MONTH 8
|
#define RUBY_RELEASE_MONTH 8
|
||||||
|
|
17
vm.c
17
vm.c
|
@ -241,6 +241,23 @@ rb_vm_pop_cfunc_frame(void)
|
||||||
vm_pop_frame(th);
|
vm_pop_frame(th);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
|
||||||
|
{
|
||||||
|
/* check skipped frame */
|
||||||
|
while (th->cfp != cfp) {
|
||||||
|
#if VMDEBUG
|
||||||
|
printf("skipped frame: %s\n", vm_frametype_name(th->cfp));
|
||||||
|
#endif
|
||||||
|
if (VM_FRAME_TYPE(th->cfp) != VM_FRAME_MAGIC_CFUNC) {
|
||||||
|
vm_pop_frame(th);
|
||||||
|
}
|
||||||
|
else { /* unlikely path */
|
||||||
|
rb_vm_pop_cfunc_frame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* obsolete */
|
/* obsolete */
|
||||||
void
|
void
|
||||||
rb_frame_pop(void)
|
rb_frame_pop(void)
|
||||||
|
|
|
@ -854,6 +854,7 @@ VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method);
|
||||||
void rb_vm_stack_to_heap(rb_thread_t *th);
|
void rb_vm_stack_to_heap(rb_thread_t *th);
|
||||||
void ruby_thread_init_stack(rb_thread_t *th);
|
void ruby_thread_init_stack(rb_thread_t *th);
|
||||||
int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp);
|
int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp);
|
||||||
|
void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
|
||||||
|
|
||||||
void rb_gc_mark_machine_stack(rb_thread_t *th);
|
void rb_gc_mark_machine_stack(rb_thread_t *th);
|
||||||
|
|
||||||
|
|
18
vm_eval.c
18
vm_eval.c
|
@ -1068,18 +1068,7 @@ rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1,
|
||||||
th->errinfo = Qnil;
|
th->errinfo = Qnil;
|
||||||
retval = GET_THROWOBJ_VAL(err);
|
retval = GET_THROWOBJ_VAL(err);
|
||||||
|
|
||||||
/* check skipped frame */
|
rb_vm_rewind_cfp(th, cfp);
|
||||||
while (th->cfp != cfp) {
|
|
||||||
#if VMDEBUG
|
|
||||||
printf("skipped frame: %s\n", vm_frametype_name(th->cfp));
|
|
||||||
#endif
|
|
||||||
if (VM_FRAME_TYPE(th->cfp) != VM_FRAME_MAGIC_CFUNC) {
|
|
||||||
vm_pop_frame(th);
|
|
||||||
}
|
|
||||||
else { /* unlikely path */
|
|
||||||
rb_vm_pop_cfunc_frame();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/* SDR(); printf("%p, %p\n", cdfp, escape_dfp); */
|
/* SDR(); printf("%p, %p\n", cdfp, escape_dfp); */
|
||||||
|
@ -1090,10 +1079,11 @@ rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1,
|
||||||
VALUE *cep = cfp->ep;
|
VALUE *cep = cfp->ep;
|
||||||
|
|
||||||
if (cep == escape_ep) {
|
if (cep == escape_ep) {
|
||||||
|
rb_vm_rewind_cfp(th, cfp);
|
||||||
|
|
||||||
state = 0;
|
state = 0;
|
||||||
th->state = 0;
|
th->state = 0;
|
||||||
th->errinfo = Qnil;
|
th->errinfo = Qnil;
|
||||||
th->cfp = cfp;
|
|
||||||
goto iter_retry;
|
goto iter_retry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1835,7 +1825,7 @@ rb_catch_obj(VALUE tag, VALUE (*func)(), VALUE data)
|
||||||
val = (*func)(tag, data, 1, &tag, Qnil);
|
val = (*func)(tag, data, 1, &tag, Qnil);
|
||||||
}
|
}
|
||||||
else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) {
|
else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) {
|
||||||
th->cfp = saved_cfp;
|
rb_vm_rewind_cfp(th, saved_cfp);
|
||||||
val = th->tag->retval;
|
val = th->tag->retval;
|
||||||
th->errinfo = Qnil;
|
th->errinfo = Qnil;
|
||||||
state = 0;
|
state = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue