From e8700ab03d78a619fadd13cee67b0c7fd135d834 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 11 Jun 2016 00:31:30 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ lib/forwardable.rb | 7 +------ test/test_forwardable.rb | 13 ++++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9afaaaaae4..3034535dbe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Jun 11 09:31:28 2016 Nobuyoshi Nakada + + * 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 * include/ruby/defines.h (GCC_VERSION_SINCE): Fix logic error by diff --git a/lib/forwardable.rb b/lib/forwardable.rb index cd88538ef7..26c5bf7463 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -113,12 +113,9 @@ module Forwardable # Version of +forwardable.rb+ FORWARDABLE_VERSION = "1.1.0" - FILE_REGEXP = %r"#{Regexp.quote(__FILE__)}" - @debug = nil class << self - # If true, __FILE__ will remain in the backtrace in the event an - # Exception is raised. + # ignored attr_accessor :debug end @@ -204,8 +201,6 @@ module Forwardable 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 diff --git a/test/test_forwardable.rb b/test/test_forwardable.rb index b948fddac0..0d3fe19213 100644 --- a/test/test_forwardable.rb +++ b/test/test_forwardable.rb @@ -225,18 +225,21 @@ class TestForwardable < Test::Unit::TestCase 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