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

ruby-changes:43298

From: nobu <ko1@a...>
Date: Sat, 11 Jun 2016 09:31:35 +0900 (JST)
Subject: [ruby-changes:43298] nobu:r55372 (trunk): forwardable.rb: backtrace

nobu	2016-06-11 09:31:30 +0900 (Sat, 11 Jun 2016)

  New Revision: 55372

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55372

  Log:
    forwardable.rb: backtrace
    
    * lib/forwardable.rb (_delegator_method): leave the backtrace
      untouched during accessor.  forwardable.rb does not appear in
      the backtrace during delegated method because of tail-call
      optimization.

  Modified files:
    trunk/ChangeLog
    trunk/lib/forwardable.rb
    trunk/test/test_forwardable.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55371)
+++ ChangeLog	(revision 55372)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 11 09:31:28 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/forwardable.rb (_delegator_method): leave the backtrace
+	  untouched during accessor.  forwardable.rb does not appear in
+	  the backtrace during delegated method because of tail-call
+	  optimization.
+
 Sat Jun 11 01:38:31 2016  Naohisa Goto  <ngotogenome@g...>
 
 	* include/ruby/defines.h (GCC_VERSION_SINCE): Fix logic error by
Index: lib/forwardable.rb
===================================================================
--- lib/forwardable.rb	(revision 55371)
+++ lib/forwardable.rb	(revision 55372)
@@ -113,12 +113,9 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L113
   # Version of +forwardable.rb+
   FORWARDABLE_VERSION = "1.1.0"
 
-  FILE_REGEXP = %r"#{Regexp.quote(__FILE__)}"
-
   @debug = nil
   class << self
-    # If true, <tt>__FILE__</tt> will remain in the backtrace in the event an
-    # Exception is raised.
+    # ignored
     attr_accessor :debug
   end
 
@@ -204,8 +201,6 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L201
         def #{ali}(*args, &block)
           begin
             #{accessor}
-          ensure
-            $@.delete_if {|s| ::Forwardable::FILE_REGEXP =~ s} if $@ and !::Forwardable::debug
           end.__send__ :#{method}, *args, &block
         end
       end
Index: test/test_forwardable.rb
===================================================================
--- test/test_forwardable.rb	(revision 55371)
+++ test/test_forwardable.rb	(revision 55372)
@@ -225,18 +225,21 @@ class TestForwardable < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/test_forwardable.rb#L225
   class Foo
     extend Forwardable
 
+    attr_accessor :bar
     def_delegator :bar, :baz
     def_delegator :caller, :itself, :c
-
-    class Exception
-    end
   end
 
   def test_backtrace_adjustment
+    obj = Foo.new
+    def (obj.bar = Object.new).baz
+      foo
+    end
     e = assert_raise(NameError) {
-      Foo.new.baz
+      obj.baz
     }
-    assert_not_match(/\/forwardable\.rb/, e.backtrace[0])
+    assert_not_match(/\/forwardable\.rb/, e.backtrace[0],
+                     proc {RubyVM::InstructionSequence.of(obj.method(:baz)).disassemble})
     assert_equal(caller(0, 1)[0], Foo.new.c[0])
   end
 

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

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