Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a8435d17ffe0
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 13130e2a34af
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Jun 11, 2018

  1. Copy the full SHA
    f03fc20 View commit details

Commits on Jun 12, 2018

  1. Merge pull request #5214 from headius/clone_proc_for_define

    Clone proc blocks as well so they have their own frame etc.
    headius authored Jun 12, 2018
    Copy the full SHA
    13130e2 View commit details
Showing with 7 additions and 11 deletions.
  1. +7 −11 core/src/main/java/org/jruby/RubyModule.java
18 changes: 7 additions & 11 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -2143,13 +2143,7 @@ public IRubyObject defineMethodFromBlock(ThreadContext context, IRubyObject arg0
}
}

block = block.cloneBlockAndFrame();
RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block);

// a normal block passed to define_method changes to do arity checking; make it a lambda
proc.getBlock().type = Block.Type.LAMBDA;

newMethod = createProcMethod(name.idString(), visibility, proc);
newMethod = createProcMethod(runtime, name.idString(), visibility, block);

Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime);

@@ -2172,7 +2166,7 @@ public IRubyObject defineMethodFromCallable(ThreadContext context, IRubyObject a
// double-testing args.length here, but it avoids duplicating the proc-setup code in two places
RubyProc proc = (RubyProc)arg1;

newMethod = createProcMethod(name.idString(), visibility, proc);
newMethod = createProcMethod(runtime, name.idString(), visibility, proc.getBlock());
} else if (arg1 instanceof AbstractRubyMethod) {
AbstractRubyMethod method = (AbstractRubyMethod)arg1;

@@ -2202,13 +2196,15 @@ public IRubyObject define_method(ThreadContext context, IRubyObject[] args, Bloc
}
}

private DynamicMethod createProcMethod(String name, Visibility visibility, RubyProc proc) {
Block block = proc.getBlock();
private DynamicMethod createProcMethod(Ruby runtime, String name, Visibility visibility, Block block) {
block = block.cloneBlockAndFrame();

block.getBinding().getFrame().setKlazz(this);
block.getBinding().getFrame().setName(name);
block.getBinding().setMethod(name);

block.type = Block.Type.LAMBDA;
// a normal block passed to define_method changes to do arity checking; make it a lambda
RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block);

// various instructions can tell this scope is not an ordinary block but a block representing
// a method definition.