Project

General

Profile

Bug #12729

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

If I am using a refinement to make a private method into a public one, and I call the method, then Ruby crashes. Here's a simple example: 

 ~~~ ruby 
 class Cow 
   private 
   def moo() end 
 end 

 module PublicCows 
   refine(Cow) { 
     public :moo 
   } 
 end 

 using PublicCows 
 Cow.new.moo 
 ~~~ 

 It segfaults: 

 ~~~ 
 $ ruby scratch.rb                                                               
 scratch.rb:13: [BUG] Segmentation fault at 0x007f7fffbbdff8 
 ruby 2.4.0dev (2016-09-06 trunk 56078) [x86_64-openbsd6.0] 

 -- Control frame information ----------------------------------------------- 
 c:0002 p:0049 s:0007 e:000005 EVAL     scratch.rb:13 [FINISH] 
 c:0001 p:0000 s:0003 E:001d50 (none) [FINISH] 

 -- Ruby level backtrace information ---------------------------------------- 
 scratch.rb:13:in `<main>' 

 -- Other runtime information ----------------------------------------------- 

 * Loaded script: scratch.rb 

 * Loaded features: 

     0 enumerator.so 
     1 thread.rb 
     2 rational.so 
     3 complex.so 
     4 /home/kernigh/prefix/lib/ruby/2.4.0/x86_64-openbsd6.0/enc/encdb.so 
     5 /home/kernigh/prefix/lib/ruby/2.4.0/x86_64-openbsd6.0/enc/trans/transdb.so 
     6 /home/kernigh/prefix/lib/ruby/2.4.0/unicode_normalize.rb 
     7 /home/kernigh/prefix/lib/ruby/2.4.0/x86_64-openbsd6.0/rbconfig.rb 
     8 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/compatibility.rb 
     9 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/defaults.rb 
    10 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/deprecate.rb 
    11 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/errors.rb 
    12 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/version.rb 
    13 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/requirement.rb 
    14 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/platform.rb 
    15 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/basic_specification.rb 
    16 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/stub_specification.rb 
    17 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/util/list.rb 
    18 /home/kernigh/prefix/lib/ruby/2.4.0/x86_64-openbsd6.0/stringio.so 
    19 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/specification.rb 
    20 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/exceptions.rb 
    21 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/dependency.rb 
    22 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/core_ext/kernel_gem.rb 
    23 /home/kernigh/prefix/lib/ruby/2.4.0/monitor.rb 
    24 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb 
    25 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems.rb 
    26 /home/kernigh/prefix/lib/ruby/2.4.0/rubygems/path_support.rb 

 [NOTE] 
 You may have encountered a bug in the Ruby interpreter or extension libraries. 
 Bug reports are welcome. 
 For details: http://www.ruby-lang.org/bugreport.html 

 Abort trap (core dumped)  
 ~~~ 

 There's a small chance that I get a `SystemStackError` SystemStackError instead of a segfault: 

 
 ~~~ 
 $ ruby scratch.rb  
 scratch.rb:13:in `<main>': stack level too deep (SystemStackError) 
 ~~~ 

 Feature #12697 had inspired me to try making a refinement where `Module#attr_accessor` Module#attr_accessor and `Module#define_method` Module#define_method are public. That's how I found this bug.

Back