When executing a method defined via define_method, the current
logic passes in a self to use. This self gets set into the binding
so that further down the stack the block invocation knows to use
the binding self as the actual self.
Work done for 1.7.5 to reduce frame costs increased the places
where we share a frame object and don't duplicate it across calls.
this caused define_method bodies to share a binding and frame for
every call, with multiple threads potentially stepping on each
other as they prepare and use that frame.
This commit makes the inner "call" method in RubyProc always
clone both the block and the frame if it intends to set the self
of the binding. This effectively isolates define_method body calls
from one another, avoiding the threading issue.
It has a side effect of breaking backref/lastline sharing across
define_method calls, which may or may not be a problem; MRI does
do this sharing, and it basically makes backref/lastline totally
unreliable and unusable within a define_method body. The current
logic makes it impossible to share backref/lastline and not share
We should audit how self is being mutated on binding and frame
throughout the system and see if there's a way to stop doing that.
Removing the self mutation would be far better than having to
clone every time.