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

Commits on Mar 22, 2015

  1. Copy the full SHA
    bcb0ed3 View commit details
  2. Copy the full SHA
    50e87d8 View commit details
  3. Copy the full SHA
    ca4a20c View commit details
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/slice_tags.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
fails:String#slice with Range calls to_int on range arguments
fails:String#slice with Range works with Range subclasses
fails:String#slice with Regexp returns subclass instances
fails:String#slice with Regexp, index returns nil if there is no capture for the given index
fails:String#slice with Regexp, index returns subclass instances
fails:String#slice with Regexp, group returns subclass instances
fails:String#slice with String taints resulting strings when other is tainted
fails:String#slice! with index calls to_int on index
fails:String#slice! with index returns the character given by the character index
Original file line number Diff line number Diff line change
@@ -464,7 +464,7 @@ public abstract static class GetIndexNode extends CoreMethodNode {
@Child private CallDispatchHeadNode getMatchDataIndexNode;
@Child private CallDispatchHeadNode includeNode;
@Child private CallDispatchHeadNode matchNode;
@Child private KernelNodes.DupNode dupNode;
@Child private CallDispatchHeadNode dupNode;
@Child private StringPrimitiveNodes.StringSubstringPrimitiveNode substringNode;

private final BranchProfile outOfBounds = BranchProfile.create();
@@ -475,9 +475,15 @@ public GetIndexNode(RubyContext context, SourceSection sourceSection) {

public GetIndexNode(GetIndexNode prev) {
super(prev);
toIntNode = prev.toIntNode;
getMatchDataIndexNode = prev.getMatchDataIndexNode;
includeNode = prev.includeNode;
matchNode = prev.matchNode;
dupNode = prev.dupNode;
substringNode = prev.substringNode;
}

public Object getIndex(RubyString string, int index, @SuppressWarnings("unused") UndefinedPlaceholder undefined) {
public Object getIndex(RubyString string, int index, UndefinedPlaceholder undefined) {
int normalizedIndex = string.normalizeIndex(index);
final ByteList bytes = string.getBytes();

@@ -500,7 +506,7 @@ public Object getIndex(VirtualFrame frame, RubyString string, Object index, Unde
}

@Specialization
public Object slice(RubyString string, RubyRange.IntegerFixnumRange range, @SuppressWarnings("unused") UndefinedPlaceholder undefined) {
public Object slice(RubyString string, RubyRange.IntegerFixnumRange range, UndefinedPlaceholder undefined) {
notDesignedForCompilation();

final String javaString = string.toString();
@@ -560,7 +566,7 @@ public Object slice(VirtualFrame frame, RubyString string, Object start, Object
}

@Specialization
public Object slice(VirtualFrame frame, RubyString string, RubyRegexp regexp, @SuppressWarnings("unused") UndefinedPlaceholder capture) {
public Object slice(VirtualFrame frame, RubyString string, RubyRegexp regexp, UndefinedPlaceholder capture) {
notDesignedForCompilation();

return slice(frame, string, regexp, 0);
@@ -590,7 +596,7 @@ public Object slice(VirtualFrame frame, RubyString string, RubyRegexp regexp, Ob
}

@Specialization
public Object slice(VirtualFrame frame, RubyString string, RubyString matchStr, @SuppressWarnings("unused") UndefinedPlaceholder undefined) {
public Object slice(VirtualFrame frame, RubyString string, RubyString matchStr, UndefinedPlaceholder undefined) {
notDesignedForCompilation();

if (includeNode == null) {
@@ -603,10 +609,10 @@ public Object slice(VirtualFrame frame, RubyString string, RubyString matchStr,
if (result) {
if (dupNode == null) {
CompilerDirectives.transferToInterpreter();
dupNode = insert(KernelNodesFactory.DupNodeFactory.create(getContext(), getSourceSection(), new RubyNode[]{}));
dupNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

return dupNode.dup(frame, matchStr);
return dupNode.call(frame, matchStr, "dup", null);
}

return nil();
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ public Object matchCommon(RubyString source, boolean operator, boolean setNamedC
final Object groupString;

if (start > -1 && end > -1) {
groupString = new RubyString(context.getCoreLibrary().getStringClass(), bytes.makeShared(start, end - start).dup());
groupString = makeString(source, start, end - start);
} else {
groupString = getContext().getCoreLibrary().getNilObject();
}
@@ -156,15 +156,14 @@ public Object matchCommon(RubyString source, boolean operator, boolean setNamedC
if (start == -1 || end == -1) {
values[n] = getContext().getCoreLibrary().getNilObject();
} else {
final RubyString groupString = new RubyString(context.getCoreLibrary().getStringClass(), bytes.makeShared(start, end - start).dup());
values[n] = groupString;
values[n] = makeString(source, start, end - start);
}
}
}

final RubyString pre = new RubyString(context.getCoreLibrary().getStringClass(), bytes.makeShared(0, region.beg[0]).dup());
final RubyString post = new RubyString(context.getCoreLibrary().getStringClass(), bytes.makeShared(region.end[0], bytes.length() - region.end[0]).dup());
final RubyString global = new RubyString(context.getCoreLibrary().getStringClass(), bytes.makeShared(region.beg[0], region.end[0] - region.beg[0]).dup());
final RubyString pre = makeString(source, 0, region.beg[0]);
final RubyString post = makeString(source, region.end[0], bytes.length() - region.end[0]);
final RubyString global = makeString(source, region.beg[0], region.end[0] - region.beg[0]);

final RubyMatchData matchObject = new RubyMatchData(context.getCoreLibrary().getMatchDataClass(), source, regex, region, values, pre, post, global);

@@ -196,7 +195,7 @@ public Object matchCommon(RubyString source, boolean operator, boolean setNamedC
final int start = region.beg[nth];
final int end = region.end[nth];
if (start != -1) {
value = new RubyString(context.getCoreLibrary().getStringClass(), bytes.makeShared(start, end - start).dup());
value = makeString(source, start, end - start);
} else {
value = getContext().getCoreLibrary().getNilObject();
}
@@ -213,6 +212,15 @@ public Object matchCommon(RubyString source, boolean operator, boolean setNamedC
}
}

private RubyString makeString(RubyString source, int start, int length) {
final RubyString ret = getContext().makeString(source.getLogicalClass(), source.getByteList().makeShared(start, length).dup());

ret.getByteList().setEncoding(source.getByteList().getEncoding());
ret.setCodeRange(source.getCodeRange());

return ret;
}

private void setFrame(Frame frame, String name, Object value) {
assert value != null;