ruby-changes:62447
From: Benoit <ko1@a...>
Date: Fri, 31 Jul 2020 21:08:15 +0900 (JST)
Subject: [ruby-changes:62447] 331fe6a88f (master): [rubygems/rubygems] Ignore internal frames in RubyGems' Kernel#warn
https://git.ruby-lang.org/ruby.git/commit/?id=331fe6a88f From 331fe6a88f96d9f986da55e003e896c2bc181db0 Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Fri, 10 Jul 2020 21:51:45 +0200 Subject: [rubygems/rubygems] Ignore internal frames in RubyGems' Kernel#warn * See https://github.com/oracle/truffleruby/issues/2046 * `<internal:` is a common prefix also used by core Ruby files in CRuby. * test_no_kernel_require_in_*warn_with_uplevel already test this. * Unfortunately just skipping `<internal:` in the Ruby implementation is not enough, because RubyGems' #warn would not skip the `<internal:` require (TruffleRuby defines #require in Ruby), and the Ruby implementation's #warn would not skip RubyGems's #require. The #caller_locations(0) look like this: warnee.rb:1:in `<top (required)>' # where #warn is called <internal:core> core/kernel.rb:234:in `gem_original_require' # not skipped by RubyGems' warn, skipped by the Ruby impl rubygems/core_ext/kernel_require.rb:54:in `require' # not skipped by the Ruby impl's warn, what would be shown without this fix warn.rb:1:in `<main>' # what would be correct warn.rb is require "warnee" warnee.rb is puts caller_locations(0), nil warn "oops", uplevel: 1 https://github.com/rubygems/rubygems/commit/7c838f7419 diff --git a/lib/rubygems/core_ext/kernel_warn.rb b/lib/rubygems/core_ext/kernel_warn.rb index 8b73902..e10a845 100644 --- a/lib/rubygems/core_ext/kernel_warn.rb +++ b/lib/rubygems/core_ext/kernel_warn.rb @@ -4,7 +4,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/core_ext/kernel_warn.rb#L4 if RUBY_VERSION >= "2.5" module Kernel - path = "#{__dir__}/" # Frames to be skipped start with this path. + rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. original_warn = method(:warn) @@ -38,7 +38,8 @@ if RUBY_VERSION >= "2.5" https://github.com/ruby/ruby/blob/trunk/lib/rubygems/core_ext/kernel_warn.rb#L38 start += 1 - unless loc.path.start_with?(path) + path = loc.path + unless path.start_with?(rubygems_path) or path.start_with?('<internal:') # Non-rubygems frames uplevel -= 1 end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/