[ruby-core:77419] [Ruby trunk Bug#12787][Feedback] Stackoverflow over when alias_method and prepend are used in combination
From:
shyouhei@...
Date:
2016-09-27 08:32:52 UTC
List:
ruby-core #77419
Issue #12787 has been updated by Shyouhei Urabe.
Status changed from Open to Feedback
Which version of ruby are you using? because I can't reproduce the stack overflow using 2.3.1 on my machine.
```
% ruby -v ~/Downloads/stackoverflow_with_alias_and_prepend
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
i am in prepend
i am in alias
I am requester in Netter
%
```
----------------------------------------
Bug #12787: Stackoverflow over when alias_method and prepend are used in combination
https://bugs.ruby-lang.org/issues/12787#change-60676
* Author: ethiraj srinivasan
* Status: Feedback
* Priority: Normal
* Assignee:
* ruby -v:
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
With Ruby 2.0 Module#prepend was used to overcome the drawbacks of alias_method_chaining. Most of the gems/projects still use alias_method_chain since they support 1.9.3 and with upcoming gems/projects using prepend for the method that is already aliased throws stackoverflow error since the aliased method and prepend method call each other and results in deadlock.
~~~ ruby
class Netter
def requester
puts " I am requester in Netter"
end
end
class Netter
def requester_with_alias
puts "i am in alias"
requester_without_alias
end
alias_method :requester_without_alias, :requester
alias_method :requester, :requester_with_alias
end
module Prepender
def requester
puts "i am in prepend"
super
end
end
Netter.prepend(Prepender)
Netter.new.requester
~~~
---Files--------------------------------
stackoverflow_with_alias_and_prepend (404 Bytes)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>