summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-24 04:12:30 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-24 04:12:30 +0000
commit9d803dfd5f1a57a6d07c27b0d95917165ba259dc (patch)
tree6e72b20923d4d47274258935b07da4afcb6ea790
parent76cffcdbf2554afbaf8018b8a6c5993bf09577c1 (diff)
* vm_trace.c (rb_tracepoint_attr_raised_exception): should not check
value before event checking. * vm_trace.c (rb_tracepoint_attr_return_value): ditto. * test/ruby/test_settracefunc.rb: add tests for TracePoint#return_value and TracePoint#raised_exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--test/ruby/test_settracefunc.rb43
-rw-r--r--vm_trace.c12
3 files changed, 59 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index fe3fc22388..60840fe221 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Sat Nov 24 13:10:14 2012 Koichi Sasada <ko1@atdot.net>
+
+ * vm_trace.c (rb_tracepoint_attr_raised_exception): should not check
+ value before event checking.
+
+ * vm_trace.c (rb_tracepoint_attr_return_value): ditto.
+
+ * test/ruby/test_settracefunc.rb: add tests for TracePoint#return_value
+ and TracePoint#raised_exception.
+
Sat Nov 24 12:47:27 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
* test/ruby/test_process.rb (TestProcess#test_setsid): "./ruby-trunk"
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index 8ddd4b79a0..9912dc9f4a 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -639,4 +639,47 @@ class TestSetTraceFunc < Test::Unit::TestCase
trace.disable
assert_equal(false, trace.enabled?)
end
+
+ def method_test_tracepoint_return_value obj
+ obj
+ end
+
+ def test_tracepoint_return_value
+ trace = TracePoint.new(:call, :return){|tp|
+ case tp.event
+ when :call
+ assert_raise(RuntimeError) {tp.return_value}
+ when :return
+ assert_equal("xyzzy", tp.return_value)
+ end
+ }
+ trace.enable{
+ method_test_tracepoint_return_value "xyzzy"
+ }
+ end
+
+ class XYZZYException < Exception; end
+ def method_test_tracepoint_raised_exception err
+ raise err
+ end
+
+ def test_tracepoint_raised_exception
+ trace = TracePoint.new(:call, :return){|tp|
+ case tp.event
+ when :call, :return
+ assert_raise(RuntimeError) { tp.raised_exception }
+ when :raise
+ assert_equal(XYZZYError, tp.raised_exception)
+ end
+ }
+ trace.enable{
+ begin
+ method_test_tracepoint_raised_exception XYZZYException
+ rescue XYZZYException
+ # ok
+ else
+ raise
+ end
+ }
+ end
end
diff --git a/vm_trace.c b/vm_trace.c
index a2ede6498b..23f412e541 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -750,15 +750,15 @@ rb_tracepoint_attr_return_value(VALUE tpval)
rb_tp_t *tp = tpptr(tpval);
tp_attr_check_active(tp);
- if (tp->trace_arg->data == Qundef) {
- rb_bug("tp_attr_return_value_m: unreachable");
- }
if (tp->trace_arg->event & (RUBY_EVENT_RETURN | RUBY_EVENT_C_RETURN)) {
/* ok */
}
else {
rb_raise(rb_eRuntimeError, "not supported by this event");
}
+ if (tp->trace_arg->data == Qundef) {
+ rb_bug("tp_attr_return_value_m: unreachable");
+ }
return tp->trace_arg->data;
}
@@ -768,15 +768,15 @@ rb_tracepoint_attr_raised_exception(VALUE tpval)
rb_tp_t *tp = tpptr(tpval);
tp_attr_check_active(tp);
- if (tp->trace_arg->data == Qundef) {
- rb_bug("tp_attr_raised_exception_m: unreachable");
- }
if (tp->trace_arg->event & (RUBY_EVENT_RAISE)) {
/* ok */
}
else {
rb_raise(rb_eRuntimeError, "not supported by this event");
}
+ if (tp->trace_arg->data == Qundef) {
+ rb_bug("tp_attr_raised_exception_m: unreachable");
+ }
return tp->trace_arg->data;
}