ruby-changes:52614
From: nobu <ko1@a...>
Date: Mon, 24 Sep 2018 23:26:05 +0900 (JST)
Subject: [ruby-changes:52614] nobu:r64826 (trunk): Check whether to skip every frame
nobu 2018-09-24 23:26:00 +0900 (Mon, 24 Sep 2018) New Revision: 64826 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64826 Log: Check whether to skip every frame Modified files: trunk/lib/rubygems/core_ext/kernel_warn.rb trunk/lib/rubygems.rb trunk/test/rubygems/test_require.rb Index: lib/rubygems/core_ext/kernel_warn.rb =================================================================== --- lib/rubygems/core_ext/kernel_warn.rb (revision 64825) +++ lib/rubygems/core_ext/kernel_warn.rb (revision 64826) @@ -9,8 +9,15 @@ if RUBY_VERSION >= "2.5" https://github.com/ruby/ruby/blob/trunk/lib/rubygems/core_ext/kernel_warn.rb#L9 module_function define_method(:warn) {|*messages, uplevel: nil| if uplevel - while (loc, = caller_locations(uplevel, 1); loc && loc.path.start_with?(path)) - uplevel += 1 + uplevel, = [uplevel].pack("l!").unpack("l!") + if uplevel >= 0 + start = 0 + begin + loc, = caller_locations(start, 1) + break start += uplevel unless loc + start += 1 + end while (loc.path.start_with?(path) or (uplevel -= 1) >= 0) + uplevel = start end original_warn.call(*messages, uplevel: uplevel) else Index: lib/rubygems.rb =================================================================== --- lib/rubygems.rb (revision 64825) +++ lib/rubygems.rb (revision 64826) @@ -1392,5 +1392,6 @@ Gem::Specification.load_defaults https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1392 require 'rubygems/core_ext/kernel_gem' require 'rubygems/core_ext/kernel_require' +require 'rubygems/core_ext/kernel_warn' Gem.use_gemdeps Index: test/rubygems/test_require.rb =================================================================== --- test/rubygems/test_require.rb (revision 64825) +++ test/rubygems/test_require.rb (revision 64826) @@ -412,6 +412,24 @@ class TestGemRequire < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L412 end end + if RUBY_VERSION >= "2.5" + def test_no_kernel_require_in_warn_with_uplevel + lib = File.realpath("../../../lib", __FILE__) + Dir.mktmpdir("warn_test") do |dir| + File.write(dir + "/sub.rb", "warn 'uplevel', 'test', uplevel: 1\n") + File.write(dir + "/main.rb", "require 'sub'\n") + _, err = capture_subprocess_io do + system(@@ruby, "-w", "-rpp", "--disable=gems", "-I", lib, "-C", dir, "-I.", "main.rb") + end + assert_equal "main.rb:1: warning: uplevel\ntest\n", err + _, err = capture_subprocess_io do + system(@@ruby, "-w", "-rpp", "--enable=gems", "-I", lib, "-C", dir, "-I.", "main.rb") + end + assert_equal "main.rb:1: warning: uplevel\ntest\n", err + end + end + end + def silence_warnings old_verbose, $VERBOSE = $VERBOSE, false yield -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/