Skip to content

Commit

Permalink
[Truffle] Removed bad transfers.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Nov 16, 2016
1 parent 629256e commit 46cfd64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Expand Up @@ -257,6 +257,11 @@ public DynamicObject errnoError(int errno, String extraMessage, Node currentNode

// IndexError

@TruffleBoundary
public DynamicObject indexErrorOutOfString(int index, Node currentNode) {
return indexError(StringUtils.format("index %d out of string", index), currentNode);
}

@TruffleBoundary
public DynamicObject indexError(String message, Node currentNode) {
return ExceptionOperations.createRubyException(
Expand Down
Expand Up @@ -2658,16 +2658,12 @@ public static class StringNodesHelper {

public static int checkIndex(int length, int index, RubyNode node) {
if (index > length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(
node.getContext().getCoreExceptions().indexError(StringUtils.format("index %d out of string", index), node));
throw new RaiseException(node.getContext().getCoreExceptions().indexErrorOutOfString(index, node));
}

if (index < 0) {
if (-index > length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(
node.getContext().getCoreExceptions().indexError(StringUtils.format("index %d out of string", index), node));
throw new RaiseException(node.getContext().getCoreExceptions().indexErrorOutOfString(index, node));
}

index += length;
Expand All @@ -2682,16 +2678,12 @@ public static int checkIndexForRef(DynamicObject string, int index, RubyNode nod
final int length = rope(string).byteLength();

if (index >= length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(
node.getContext().getCoreExceptions().indexError(StringUtils.format("index %d out of string", index), node));
throw new RaiseException(node.getContext().getCoreExceptions().indexErrorOutOfString(index, node));
}

if (index < 0) {
if (-index > length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(
node.getContext().getCoreExceptions().indexError(StringUtils.format("index %d out of string", index), node));
throw new RaiseException(node.getContext().getCoreExceptions().indexErrorOutOfString(index, node));
}

index += length;
Expand Down

0 comments on commit 46cfd64

Please sign in to comment.