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: eee1188156fc
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 071ad5bbbdca
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Apr 11, 2015

  1. Copy the full SHA
    42dcef1 View commit details
  2. Copy the full SHA
    a3888ff View commit details
  3. Copy the full SHA
    071ad5b View commit details
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -4128,6 +4128,8 @@ public RubyString pack(ThreadContext context, IRubyObject obj) {
throw context.getRuntime().newRangeError(e.getMessage());
} catch (CantConvertException e) {
throw context.getRuntime().newTypeError(e.getMessage());
} catch (WrongArgumentTypeException e) {
throw context.getRuntime().newTypeError("wrong argument type " + e.getGot() + " (expected " + e.getExpected() + ")");
}

final RubyString string = context.getRuntime().newString(new ByteList(result.getOutput(), 0, result.getOutputLength()));
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.pack.runtime.exceptions;

public class WrongArgumentTypeException extends RuntimeException {

private final String got;
private final String expected;

public WrongArgumentTypeException(String got, String expected) {
this.got = got;
this.expected = expected;
}

public String getGot() {
return got;
}

public String getExpected() {
return expected;
}

}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.pack.nodes.SourceNode;
import org.jruby.truffle.pack.runtime.exceptions.WrongArgumentTypeException;
import org.jruby.truffle.runtime.RubyContext;

/**
@@ -65,7 +66,11 @@ public double read(VirtualFrame frame, IRubyObject[] source) {

@CompilerDirectives.TruffleBoundary
private double toDouble(IRubyObject object) {
return object.convertToFloat().getDoubleValue();
if (object.isNil()) {
throw new WrongArgumentTypeException("NilClass", "Float");
} else {
return object.convertToFloat().getDoubleValue();
}
}

}
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.RubyInteger;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.pack.nodes.SourceNode;
@@ -88,13 +89,19 @@ public Object read(VirtualFrame frame, Object[] source) {
}

@Specialization
public long read(VirtualFrame frame, IRubyObject[] source) {
return toLong(source[advanceSourcePosition(frame)]);
public Object read(VirtualFrame frame, IRubyObject[] source) {
return toLongOrBigInteger(source[advanceSourcePosition(frame)]);
}

@CompilerDirectives.TruffleBoundary
private long toLong(IRubyObject object) {
return object.convertToInteger().getLongValue();
private Object toLongOrBigInteger(IRubyObject object) {
final RubyInteger integer = object.convertToInteger();

if (integer instanceof org.jruby.RubyBignum) {
return integer.getBigIntegerValue().longValue();
} else {
return integer.getLongValue();
}
}

}
Original file line number Diff line number Diff line change
@@ -88,12 +88,18 @@ private Object readAndConvert(VirtualFrame frame, Object value) {

@Specialization
public ByteList read(VirtualFrame frame, IRubyObject[] source) {
return toString(source[advanceSourcePosition(frame)]);
final org.jruby.RubyString string = toString(source[advanceSourcePosition(frame)]);

if (string.isTaint()) {
setTainted(frame);
}

return string.getByteList();
}

@CompilerDirectives.TruffleBoundary
private ByteList toString(IRubyObject object) {
return object.convertToString().getByteList();
private org.jruby.RubyString toString(IRubyObject object) {
return object.convertToString();
}

}