summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-16 14:39:02 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-16 14:39:02 +0000
commit9b03ab6f93b68d5d0e4f775a095dab813b3efdfd (patch)
tree9c886b884ce3e626139848600472ae331b4813f5
parenta658ebd5bc1f3826d13e22612b9476fd7b5b306a (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--ChangeLog6
-rw-r--r--eval.c27
-rw-r--r--test/ruby/test_settracefunc.rb20
3 files changed, 33 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 6b2485b0c9..5f1793ab47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/eval.c b/eval.c
index 550f658ede..54764f588b 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 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