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

Commits on Jun 22, 2016

  1. Copy the full SHA
    744f999 View commit details
  2. Copy the full SHA
    3f02675 View commit details
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*
* Some of the code in this class is modified from org.jruby.runtime.encoding.EncodingService,
* licensed under the same EPL1.0/GPL 2.0/LGPL 2.1 used throughout.
*/
package org.jruby.truffle.core.encoding;

Original file line number Diff line number Diff line change
@@ -9,8 +9,12 @@
*/
package org.jruby.truffle.core.string;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.object.DynamicObject;
import org.jcodings.Encoding;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.encoding.EncodingNodes;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;
@@ -70,8 +74,20 @@ public final void modifyAndKeepCodeRange() {
}

@Override
@TruffleBoundary(throwsControlFlowException = true)
public Encoding checkEncoding(CodeRangeable other) {
return StringOperations.checkEncoding(string, other);
final Encoding encoding = EncodingNodes.CompatibleQueryNode.compatibleEncodingForStrings(string, ((StringCodeRangeableWrapper) other).getString());

// TODO (nirvdrum 23-Mar-15) We need to raise a proper Truffle+JRuby exception here, rather than a non-Truffle JRuby exception.
if (encoding == null) {
final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext();
throw context.getJRubyRuntime().newEncodingCompatibilityError(
String.format("incompatible character encodings: %s and %s",
Layouts.STRING.getRope(string).getEncoding().toString(),
other.getByteList().getEncoding().toString()));
}

return encoding;
}

@Override
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;

import java.nio.charset.Charset;

@@ -134,22 +133,6 @@ public static void keepCodeRange(DynamicObject string) {
}
}

@TruffleBoundary(throwsControlFlowException = true)
public static Encoding checkEncoding(DynamicObject string, CodeRangeable other) {
final Encoding encoding = EncodingNodes.CompatibleQueryNode.compatibleEncodingForStrings(string, ((StringCodeRangeableWrapper) other).getString());

// TODO (nirvdrum 23-Mar-15) We need to raise a proper Truffle+JRuby exception here, rather than a non-Truffle JRuby exception.
if (encoding == null) {
final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext();
throw context.getJRubyRuntime().newEncodingCompatibilityError(
String.format("incompatible character encodings: %s and %s",
Layouts.STRING.getRope(string).getEncoding().toString(),
other.getByteList().getEncoding().toString()));
}

return encoding;
}

public static int normalizeIndex(int length, int index) {
return ArrayOperations.normalizeIndex(length, index);
}