From b30c83be514f86dde8ca0e455af7da62dd61c3fa Mon Sep 17 00:00:00 2001 From: shugo Date: Wed, 16 Mar 2005 14:39:02 +0000 Subject: * eval.c (rb_call0): call_cfunc() should be protected. * test/ruby/test_settracefunc.rb: added test for c-return. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ eval.c | 27 ++++++++++++++++----------- test/ruby/test_settracefunc.rb | 20 +++++++++++--------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b2485b0c..5f1793ab4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Mar 16 23:36:02 2005 Shugo Maeda + + * eval.c (rb_call0): call_cfunc() should be protected. + + * test/ruby/test_settracefunc.rb: added test for c-return. + Wed Mar 16 22:20:25 2005 Hirokazu Yamamoto * object.c (str_to_id): fixed typo. diff --git a/eval.c b/eval.c index 550f658ed..54764f588 100644 --- a/eval.c +++ b/eval.c @@ -5470,7 +5470,6 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) volatile VALUE result = Qnil; int itr; static int tick; - volatile int trace_status = 0; /* 0:none 1:cfunc 2:rfunc */ TMP_PROTECT; switch (ruby_iter->iter) { @@ -5508,10 +5507,21 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) len, rb_class2name(klass), rb_id2name(id)); } if (trace_func) { + int state; + call_trace_func("c-call", ruby_current_node, recv, id, klass); - trace_status = 1; /* cfunc */ + PUSH_TAG(PROT_FUNC); + if ((state = EXEC_TAG()) == 0) { + result = call_cfunc(body->nd_cfnc, recv, len, argc, argv); + } + POP_TAG(); + ruby_current_node = ruby_frame->node; + call_trace_func("c-return", ruby_current_node, recv, id, klass); + if (state) JUMP_TAG(state); + } + else { + result = call_cfunc(body->nd_cfnc, recv, len, argc, argv); } - result = call_cfunc(body->nd_cfnc, recv, len, argc, argv); } break; @@ -5542,6 +5552,7 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) int state; VALUE *local_vars; /* OK */ NODE *saved_cref = 0; + int trace_return = 0; PUSH_SCOPE(); @@ -5637,7 +5648,7 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) if (trace_func) { call_trace_func("call", b2, recv, id, klass); - trace_status = 2; /* rfunc */ + trace_return = 1; } result = rb_eval(recv, body); } @@ -5650,14 +5661,8 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) POP_CLASS(); POP_SCOPE(); ruby_cref = saved_cref; - switch (trace_status) { - case 0: break; /* none */ - case 1: /* cfunc */ - call_trace_func("c-return", body, recv, id, klass); - break; - case 2: /* rfunc */ + if (trace_return) { call_trace_func("return", body, recv, id, klass); - break; } switch (state) { case 0: diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index f1eb47b75..e8ac6e2ab 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -11,16 +11,18 @@ class TestSetTraceFunc < Test::Unit::TestCase a = 1 foo a + b = 1 + 2 set_trace_func nil - assert_equal(["line", 11], events.shift) # line "a = 1" - assert_equal(["line", 12], events.shift) # line "foo" - assert_equal(["call", 4], events.shift) # call foo - event, lineno = events.shift # return - assert_equal("return", event) - assert_not_equal(4, lineno)# it should be 4 but cannot be expected in 1.8 - assert_equal(["line", 13], events.shift) # line "a" - assert_equal(["line", 14], events.shift) # line "set_trace_func nil" - assert_equal(["c-call", 14], events.shift) # c-call set_trace_func + assert_equal(["line", 11], events.shift) # line "a = 1" + assert_equal(["line", 12], events.shift) # line "foo" + assert_equal(["call", 4], events.shift) # call foo + assert_equal(["return", 4], events.shift) # return foo + assert_equal(["line", 13], events.shift) # line "a" + assert_equal(["line", 14], events.shift) # line "b = 1 + 2" + assert_equal(["c-call", 14], events.shift) # c-call Fixnum#+ + assert_equal(["c-return", 14], events.shift) # c-return Fixnum#+ + assert_equal(["line", 15], events.shift) # line "set_trace_func nil" + assert_equal(["c-call", 15], events.shift) # c-call set_trace_func end end -- cgit