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: 4e9c4b96625c^
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1403014192bb
Choose a head ref
  • 2 commits
  • 8 files changed
  • 1 contributor

Commits on Jan 31, 2016

  1. Copy the full SHA
    4e9c4b9 View commit details
  2. Copy the full SHA
    1403014 View commit details
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
NaN = Float::NAN

def assert_equal(one, two)
raise "Expected size: `#{one.b.size}` Actual size: `#{two.size}`" if one.b.size != two.size
raise "Expected: `#{one.b}` Actual: `#{two}`" if one.b != two
end

Original file line number Diff line number Diff line change
@@ -61,7 +61,9 @@
import org.jruby.truffle.runtime.methods.Arity;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.runtime.rope.AsciiOnlyLeafRope;
import org.jruby.truffle.runtime.rope.Rope;
import org.jruby.truffle.runtime.rope.ValidLeafRope;
import org.jruby.util.Memo;
import org.jruby.util.StringSupport;

@@ -2487,7 +2489,13 @@ private DynamicObject finishPack(int formatLength, PackResult result) {
}
}

final Rope rope = makeLeafRopeNode.executeMake(bytes, encoding, StringSupport.CR_UNKNOWN);
/*
* TODO CS 31-Jan-16 what can I usefully do with the code range? Create AsciiOnlyLeafRope? I'm not setting
* it in the pack nodes yet so it's always just VALID. Also can I use an AsciiOnlyLeafRope for a binary
* string that has bytes with the MSB set?
*/

final Rope rope = new ValidLeafRope(bytes, encoding, result.getStringLength());
final DynamicObject string = createString(rope);

if (result.isTainted()) {
Original file line number Diff line number Diff line change
@@ -154,6 +154,26 @@ protected void setOutputPosition(VirtualFrame frame, int position) {
frame.setInt(PackFrameDescriptor.OUTPUT_POSITION_SLOT, position);
}

protected int getStringLength(VirtualFrame frame) {
try {
return frame.getInt(PackFrameDescriptor.STRING_LENGTH_SLOT);
} catch (FrameSlotTypeException e) {
throw new IllegalStateException(e);
}
}

protected void setStringLength(VirtualFrame frame, int length) {
frame.setInt(PackFrameDescriptor.STRING_LENGTH_SLOT, length);
}

protected void increaseStringLength(VirtualFrame frame, int additionalLength) {
setStringLength(frame, getStringLength(frame) + additionalLength);
}

protected void setStringCodeRange(VirtualFrame frame, int codeRange) {
frame.setInt(PackFrameDescriptor.STRING_CODE_RANGE_SLOT, codeRange);
}

/**
* Set the output to be tainted.
*/
@@ -169,6 +189,7 @@ protected void writeByte(VirtualFrame frame, byte value) {
final int outputPosition = getOutputPosition(frame);
output[outputPosition] = value;
setOutputPosition(frame, outputPosition + 1);
increaseStringLength(frame, 1);
}

/**
@@ -193,6 +214,7 @@ protected void writeBytes(VirtualFrame frame, byte[] values, int valuesStart, in
final int outputPosition = getOutputPosition(frame);
System.arraycopy(values, valuesStart, output, outputPosition, valuesLength);
setOutputPosition(frame, outputPosition + valuesLength);
increaseStringLength(frame, valuesLength);
}

/**
@@ -203,6 +225,7 @@ protected void writeNullBytes(VirtualFrame frame, int length) {
ensureCapacity(frame, length);
final int outputPosition = getOutputPosition(frame);
setOutputPosition(frame, outputPosition + length);
increaseStringLength(frame, length);
}
}

Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.core.format.runtime.PackFrameDescriptor;
import org.jruby.truffle.core.format.runtime.PackResult;
import org.jruby.truffle.runtime.RubyLanguage;
import org.jruby.util.StringSupport;

/**
* The node at the root of a pack expression.
@@ -46,6 +47,8 @@ public Object execute(VirtualFrame frame) {
frame.setInt(PackFrameDescriptor.SOURCE_POSITION_SLOT, 0);
frame.setObject(PackFrameDescriptor.OUTPUT_SLOT, new byte[expectedLength]);
frame.setInt(PackFrameDescriptor.OUTPUT_POSITION_SLOT, 0);
frame.setInt(PackFrameDescriptor.STRING_LENGTH_SLOT, 0);
frame.setInt(PackFrameDescriptor.STRING_CODE_RANGE_SLOT, StringSupport.CR_7BIT);
frame.setBoolean(PackFrameDescriptor.TAINT_SLOT, false);

child.execute(frame);
@@ -79,7 +82,27 @@ public Object execute(VirtualFrame frame) {
throw new IllegalStateException(e);
}

return new PackResult(output, outputLength, taint, encoding);
final int stringLength;

if (encoding == PackEncoding.UTF_8) {
try {
stringLength = frame.getInt(PackFrameDescriptor.STRING_LENGTH_SLOT);
} catch (FrameSlotTypeException e) {
throw new IllegalStateException(e);
}
} else {
stringLength = outputLength;
}

final int stringCodeRange;

try {
stringCodeRange = frame.getInt(PackFrameDescriptor.STRING_CODE_RANGE_SLOT);
} catch (FrameSlotTypeException e) {
throw new IllegalStateException(e);
}

return new PackResult(output, outputLength, stringLength, stringCodeRange, taint, encoding);
}

@Override
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public Object execute(VirtualFrame frame) {
throw new IllegalStateException(e);
}

return new PackResult(output, outputLength, taint, encoding);
return new PackResult(output, outputLength, -1, -1, taint, encoding);
}

@Override
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ public Object writeTwoBytes(VirtualFrame frame, long value) {
writeBytes(frame,
(byte)(((value >>> 6) & 0xff) | 0xc0),
(byte)((value & 0x3f) | 0x80));
increaseStringLength(frame, -2 + 1);
return null;
}

@@ -53,6 +54,7 @@ public Object writeThreeBytes(VirtualFrame frame, long value) {
(byte)(((value >>> 12) & 0xff) | 0xe0),
(byte)(((value >>> 6) & 0x3f) | 0x80),
(byte)((value & 0x3f) | 0x80));
increaseStringLength(frame, -3 + 1);
return null;
}

@@ -63,6 +65,7 @@ public Object writeFourBytes(VirtualFrame frame, long value) {
(byte)(((value >>> 12) & 0x3f) | 0x80),
(byte)(((value >>> 6) & 0x3f) | 0x80),
(byte)((value & 0x3f) | 0x80));
increaseStringLength(frame, -4 + 1);
return null;
}

@@ -74,6 +77,7 @@ public Object writeFiveBytes(VirtualFrame frame, long value) {
(byte)(((value >>> 12) & 0x3f) | 0x80),
(byte)(((value >>> 6) & 0x3f) | 0x80),
(byte)((value & 0x3f) | 0x80));
increaseStringLength(frame, -5 + 1);
return null;
}

@@ -86,6 +90,7 @@ public Object writeSixBytes(VirtualFrame frame, long value) {
(byte)(((value >>> 12) & 0x3f) | 0x80),
(byte)(((value >>> 6) & 0x3f) | 0x80),
(byte)((value & 0x3f) | 0x80));
increaseStringLength(frame, -6 + 1);
return null;
}

Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ public class PackFrameDescriptor {
public static final FrameSlot SOURCE_POSITION_SLOT = FRAME_DESCRIPTOR.addFrameSlot("source-position", FrameSlotKind.Int);
public static final FrameSlot OUTPUT_SLOT = FRAME_DESCRIPTOR.addFrameSlot("output", FrameSlotKind.Object);
public static final FrameSlot OUTPUT_POSITION_SLOT = FRAME_DESCRIPTOR.addFrameSlot("output-position", FrameSlotKind.Int);
public static final FrameSlot STRING_LENGTH_SLOT = FRAME_DESCRIPTOR.addFrameSlot("string-length", FrameSlotKind.Int);
public static final FrameSlot STRING_CODE_RANGE_SLOT = FRAME_DESCRIPTOR.addFrameSlot("string-code-range", FrameSlotKind.Int);
public static final FrameSlot TAINT_SLOT = FRAME_DESCRIPTOR.addFrameSlot("taint", FrameSlotKind.Boolean);

}
Original file line number Diff line number Diff line change
@@ -13,12 +13,16 @@ public class PackResult {

private final Object output;
private final int outputLength;
private final int stringLength;
private final int stringCodeRange;
private final boolean tainted;
private final PackEncoding encoding;

public PackResult(Object output, int outputLength, boolean tainted, PackEncoding encoding) {
public PackResult(Object output, int outputLength, int stringLength, int stringCodeRange, boolean tainted, PackEncoding encoding) {
this.output = output;
this.outputLength = outputLength;
this.stringLength = stringLength;
this.stringCodeRange = stringCodeRange;
this.tainted = tainted;
this.encoding = encoding;
}
@@ -31,6 +35,14 @@ public int getOutputLength() {
return outputLength;
}

public int getStringLength() {
return stringLength;
}

public int getStringCodeRange() {
return stringCodeRange;
}

public boolean isTainted() {
return tainted;
}