[前][次][番号順一覧][スレッド一覧]

ruby-changes:25773

From: ko1 <ko1@a...>
Date: Sat, 24 Nov 2012 13:12:38 +0900 (JST)
Subject: [ruby-changes:25773] ko1:r37830 (trunk): * vm_trace.c (rb_tracepoint_attr_raised_exception): should not check

ko1	2012-11-24 13:12:30 +0900 (Sat, 24 Nov 2012)

  New Revision: 37830

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37830

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_settracefunc.rb
    trunk/vm_trace.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37829)
+++ ChangeLog	(revision 37830)
@@ -1,3 +1,13 @@
+Sat Nov 24 13:10:14 2012  Koichi Sasada  <ko1@a...>
+
+	* 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@g...>
 
 	* test/ruby/test_process.rb (TestProcess#test_setsid): "./ruby-trunk"
Index: vm_trace.c
===================================================================
--- vm_trace.c	(revision 37829)
+++ vm_trace.c	(revision 37830)
@@ -750,15 +750,15 @@
     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_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;
 }
 
Index: test/ruby/test_settracefunc.rb
===================================================================
--- test/ruby/test_settracefunc.rb	(revision 37829)
+++ test/ruby/test_settracefunc.rb	(revision 37830)
@@ -639,4 +639,47 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]