Skip to content

Commit

Permalink
Make sure call19 path uses new Signature class for LAMBDA arity check…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
enebo committed Jan 19, 2015
1 parent 2d033dc commit 2025534
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
22 changes: 12 additions & 10 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.JumpException;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.lexer.yacc.SimpleSourcePosition;
import org.jruby.parser.StaticScope;
Expand All @@ -46,6 +45,7 @@
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.InterpretedIRBlockBody;
import org.jruby.runtime.MethodBlock;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -238,17 +238,19 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args) {
* For others, transforms the given arguments appropriately for the given arity (i.e. trimming to one arg for fixed
* arity of one, etc.)
*/
public static IRubyObject[] prepareArgs(ThreadContext context, Block.Type type, Arity arity, IRubyObject[] args) {
if (arity == null) {
return args;
}
public static IRubyObject[] prepareArgs(ThreadContext context, Block.Type type, BlockBody blockBody, IRubyObject[] args) {
// FIXME: Arity marked for death
Arity arity = blockBody.arity();
if (arity == null) return args;

if (args == null) {
return IRubyObject.NULL_ARRAY;
}
if (args == null) return IRubyObject.NULL_ARRAY;

if (type == Block.Type.LAMBDA) {
arity.checkArity(context.runtime, args.length);
if (blockBody instanceof InterpretedIRBlockBody) {
((InterpretedIRBlockBody) blockBody).getSignature().checkArity(context.runtime, args);
} else {
arity.checkArity(context.runtime, args.length);
}
return args;
}

Expand Down Expand Up @@ -282,7 +284,7 @@ public static IRubyObject[] prepareArgs(ThreadContext context, Block.Type type,

@JRubyMethod(name = {"call", "[]", "yield", "==="}, rest = true)
public IRubyObject call19(ThreadContext context, IRubyObject[] args, Block blockCallArg) {
IRubyObject[] preppedArgs = prepareArgs(context, type, block.arity(), args);
IRubyObject[] preppedArgs = prepareArgs(context, type, block.getBody(), args);

return call(context, preppedArgs, null, blockCallArg);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private IRubyObject yieldInner(ThreadContext context, RubyArray array, Block blo
@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self,
Binding binding, Type type, Block block) {
RubyProc.prepareArgs(context, type, block.arity(), args);
RubyProc.prepareArgs(context, type, block.getBody(), args);
return yieldInner(context, context.runtime.newArrayNoCopyLight(args), block);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/BlockBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public final IRubyObject yield(ThreadContext context, IRubyObject value, Binding

public final IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self,
Binding binding, Block.Type type) {
IRubyObject[] preppedValue = RubyProc.prepareArgs(context, type, arity(), args);
IRubyObject[] preppedValue = RubyProc.prepareArgs(context, type, this, args);
return doYield(context, preppedValue, self, binding, type);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/CompiledBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject
// SSS FIXME: This is now being done unconditionally compared to if (klass == null) earlier
self = prepareSelf(binding);

IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, arity, args);
IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, this, args);
RubyArray value = context.runtime.newArrayNoCopyLight(preppedArgs);
IRubyObject realArg = setupBlockArgs(context, value, self);
Visibility oldVis = binding.getFrame().getVisibility();
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/CompiledBlock19.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject
Frame lastFrame = pre(context, binding);

try {
IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, arity, args);
IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, this, args);
IRubyObject[] realArgs = setupBlockArgs(context.runtime.newArrayNoCopyLight(preppedArgs), type, true);
return callback.call(context, self, realArgs, block);
} catch (JumpException.FlowControlException jump) {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/runtime/MethodBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.jruby.RubyProc;
import org.jruby.exceptions.JumpException;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.backtrace.BacktraceElement;
import org.jruby.runtime.builtin.IRubyObject;

/**
Expand Down Expand Up @@ -160,7 +159,7 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject
// This while loop is for restarting the block call in case a 'redo' fires.
while (true) {
try {
IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, arity, args);
IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, this, args);
return callback(context.runtime.newArrayNoCopyLight(preppedArgs), method, self, block);
} catch (JumpException.RedoJump rj) {
context.pollThreadEvents();
Expand Down

0 comments on commit 2025534

Please sign in to comment.