diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-03-16 14:39:02 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-03-16 14:39:02 +0000 |
commit | 9b03ab6f93b68d5d0e4f775a095dab813b3efdfd (patch) | |
tree | 9c886b884ce3e626139848600472ae331b4813f5 | |
parent | a658ebd5bc1f3826d13e22612b9476fd7b5b306a (diff) |
* eval.c (rb_call0): call_cfunc() should be protected.
* test/ruby/test_settracefunc.rb: added test for c-return.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | eval.c | 27 | ||||
-rw-r--r-- | test/ruby/test_settracefunc.rb | 20 |
3 files changed, 33 insertions, 20 deletions
@@ -1,3 +1,9 @@ +Wed Mar 16 23:36:02 2005 Shugo Maeda <shugo@ruby-lang.org> + + * 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 <ocean@m2.ccsnet.ne.jp> * object.c (str_to_id): fixed typo. @@ -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 f1eb47b759..e8ac6e2abb 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 |