Project

General

Profile

Bug #4881

super() in define_method which returns proc causes SEGV

Added by enebo (Thomas Enebo) about 9 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
Backport:
[ruby-core:37116]

Description

In working through some corner cases, we ran across (https://gist.github.com/1023643):

class Base
def foo
puts "Base foo"
end

def bar
puts "Base bar"
end
end

class Derived < Base
def bar
self.class.send(:define_method, :foo) do
proc { super() }
end
end
end

d = Derived.new
code = d.bar
d.foo.call

And this ends up generating a SEGV:

ruby super2.rb
super2.rb:15: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]

-- control frame ----------
c:0006 p:0008 s:0016 b:0015 l:000a18 d:000014 BLOCK super2.rb:15
c:0005 p:---- s:0013 b:0013 l:000012 d:000012 FINISH
c:0004 p:---- s:0011 b:0011 l:000010 d:000010 CFUNC :call
c:0003 p:0075 s:0008 b:0008 l:0014f8 d:0003c8 EVAL super2.rb:22
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH

c:0001 p:0000 s:0002 b:0002 l:0014f8 d:0014f8 TOP

-- Ruby level backtrace information ----------------------------------------
super2.rb:22:in <main>'
super2.rb:22:in
call'
super2.rb:15:in `block (2 levels) in bar'

-- C level backtrace information -------------------------------------------

[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


This should print out that it is calling foo in the base class.


Files

raise_super_outside_of_method.patch (587 Bytes) raise_super_outside_of_method.patch nagachika (Tomoyuki Chikanaga), 06/25/2011 10:00 PM

Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago

Hi,

Thank you for your reporting.
This issue seems similar to #2420 and #3136 .
According to discussion in #3136, fundamental fix needs tough work.

I've wrote quick fix patch for only avoid SEGV but raise an NoMethodError exception.

#2

Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32227.
Thomas, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • vm_insnhelper.c (vm_search_superclass): avoid control frame stack overrun. currently super() in Proc created in a method defined by Module#define_method raise NoMethodError. [Bug #4881]
  • test/ruby/test_method.rb t_super_in_proc_from_define_method): add test for it.

Also available in: Atom PDF