Skip to content

Commit

Permalink
Showing 15 changed files with 49 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public int spawn(DynamicObject command,
Collection<SpawnFileAction> fileActions = parseOptions(options);

final long longPid = call(
StringOperations.getString(getContext(), command),
StringOperations.getString(command),
toStringArray(arguments),
toStringArray(environmentVariables),
fileActions);
@@ -70,7 +70,7 @@ private String[] toStringArray(DynamicObject rubyStrings) {

for (int i = 0; i < size; i++) {
assert Layouts.STRING.isString(unconvertedStrings[i]);
strings[i] = StringOperations.getString(getContext(), (DynamicObject) unconvertedStrings[i]);
strings[i] = StringOperations.getString((DynamicObject) unconvertedStrings[i]);
}

return strings;
@@ -111,7 +111,7 @@ private Collection<SpawnFileAction> parseOptions(DynamicObject options) {
final Object[] store = ArrayOperations.toObjectArray(array);
for (int i = 0; i < size; i += 4) {
int fd = (int) store[i];
String path = StringOperations.getString(getContext(), (DynamicObject) store[i + 1]);
String path = StringOperations.getString((DynamicObject) store[i + 1]);
int flags = (int) store[i + 2];
int perms = (int) store[i + 3];
actions.add(SpawnFileAction.open(path, fd, flags, perms));
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ String stringCached(DynamicObject value,

@Specialization(guards = "isRubyString(value)", contains = "stringCached")
public String stringUncached(DynamicObject value) {
return StringOperations.getString(getContext(), value);
return StringOperations.getString(value);
}

@Specialization(guards = { "symbol == cachedSymbol", "isRubySymbol(cachedSymbol)" }, limit = "getLimit()")
@@ -92,7 +92,7 @@ public String coerceObjectToStr(VirtualFrame frame, Object object,
}

if (RubyGuards.isRubyString(coerced)) {
return StringOperations.getString(getContext(), (DynamicObject) coerced);
return StringOperations.getString((DynamicObject) coerced);
} else {
errorProfile.enter();
throw new RaiseException(coreExceptions().typeErrorBadCoercion(object, "String", "to_str", coerced, this));
Original file line number Diff line number Diff line change
@@ -14,15 +14,18 @@
import com.oracle.truffle.api.object.DynamicObject;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jcodings.specific.ISO8859_16Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.util.ByteList;
import org.jruby.util.encoding.ISO_8859_16;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@@ -93,13 +96,27 @@ public void defineAlias(int encodingListIndex, String name) {
}

@TruffleBoundary
public Charset charsetForEncoding(Encoding encoding) {
return context.getJRubyRuntime().getEncodingService().charsetForEncoding(encoding);
public Encoding getLocaleEncoding() {
return context.getJRubyRuntime().getEncodingService().getLocaleEncoding();
}

@TruffleBoundary
public Encoding getLocaleEncoding() {
return context.getJRubyRuntime().getEncodingService().getLocaleEncoding();
public static Charset charsetForEncoding(Encoding encoding) {
Charset charset = encoding.getCharset();

if (encoding.toString().equals("ASCII-8BIT")) {
return Charset.forName("ISO-8859-1");
}

if (encoding == ISO8859_16Encoding.INSTANCE) {
return ISO_8859_16.INSTANCE;
}

try {
return Charset.forName(encoding.toString());
} catch (UnsupportedCharsetException uce) {
throw new UnsupportedOperationException("no java.nio.charset.Charset found for encoding `" + encoding.toString() + "'", uce);
}
}

}
Original file line number Diff line number Diff line change
@@ -60,7 +60,6 @@
import org.jruby.truffle.core.cast.NameToSymbolOrStringNodeGen;
import org.jruby.truffle.core.cast.ToPathNodeGen;
import org.jruby.truffle.core.cast.ToStrNodeGen;
import org.jruby.truffle.core.encoding.EncodingNodes;
import org.jruby.truffle.core.encoding.EncodingOperations;
import org.jruby.truffle.core.format.BytesResult;
import org.jruby.truffle.core.format.FormatExceptionTranslator;
@@ -653,7 +652,7 @@ private CodeLoader.DeferredCall doEvalX(DynamicObject rubySource,
// TODO (pitr 15-Oct-2015): fix this ugly hack, required for AS, copy-paste
final String space = new String(new char[Math.max(line - 1, 0)]).replace("\0", "\n");
// TODO CS 14-Apr-15 concat space + code as a rope, otherwise the string will be copied after the rope is converted
final Source source = Source.fromText(space + RopeOperations.decodeRope(getContext(), code), filename);
final Source source = Source.fromText(space + RopeOperations.decodeRope(code), filename);

final MaterializedFrame frame = Layouts.BINDING.getFrame(binding);
final DeclarationContext declarationContext = RubyArguments.getDeclarationContext(frame);
@@ -1394,7 +1393,7 @@ public RubyNode coerceFeatureToPath(RubyNode feature) {
public boolean require(VirtualFrame frame, DynamicObject featureString,
@Cached("create()") RequireNode requireNode) {

String feature = StringOperations.getString(getContext(), featureString);
String feature = StringOperations.getString(featureString);

// Pysch loads either the jar or the so - we need to intercept
if (feature.equals("psych.so") && callerIs("stdlib/psych.rb")) {
@@ -1430,7 +1429,7 @@ public abstract static class RequireRelativeNode extends CoreMethodArrayArgument
@Specialization(guards = "isRubyString(feature)")
public boolean requireRelative(VirtualFrame frame, DynamicObject feature,
@Cached("create()") RequireNode requireNode) {
final String featureString = StringOperations.getString(getContext(), feature);
final String featureString = StringOperations.getString(feature);
final String featurePath = getFullPath(featureString);

return requireNode.executeRequire(frame, featurePath);
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ public boolean load(VirtualFrame frame, DynamicObject file, boolean wrap,
}

try {
final RubyRootNode rootNode = getContext().getCodeLoader().parse(getContext().getSourceCache().getSource(StringOperations.getString(getContext(), file)), UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, null, true, this);
final RubyRootNode rootNode = getContext().getCodeLoader().parse(getContext().getSourceCache().getSource(StringOperations.getString(file)), UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, null, true, this);
final CodeLoader.DeferredCall deferredCall = getContext().getCodeLoader().prepareExecute(ParserContext.TOP_LEVEL, DeclarationContext.TOP_LEVEL, rootNode, null, getContext().getCoreLibrary().getMainObject());
deferredCall.call(frame, callNode);
} catch (IOException e) {
Original file line number Diff line number Diff line change
@@ -922,7 +922,7 @@ private void loadAutoloadedConstant(VirtualFrame frame, RubyConstant constant) {
requireNode = insert(RequireNode.create());
}

final String feature = StringOperations.getString(getContext(), (DynamicObject) constant.getValue());
final String feature = StringOperations.getString((DynamicObject) constant.getValue());
requireNode.executeRequire(frame, feature);
}

Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
import org.jruby.RubyEncoding;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.encoding.EncodingManager;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.util.ByteList;
@@ -123,7 +124,7 @@ public static String decodeUTF8(byte[] bytes, int offset, int byteLength) {
}

@TruffleBoundary
public static String decodeRope(RubyContext context, Rope value) {
public static String decodeRope(Rope value) {
// TODO CS 9-May-16 having recursive problems with this, so flatten up front for now

value = flatten(value);
@@ -141,7 +142,7 @@ public static String decodeRope(RubyContext context, Rope value) {
Charset charset = encodingToCharsetMap.get(encoding);

if (charset == null) {
charset = context.getEncodingManager().charsetForEncoding(encoding);
charset = EncodingManager.charsetForEncoding(encoding);
encodingToCharsetMap.put(encoding, charset);
}

@@ -593,7 +594,7 @@ public static Rope format(RubyContext context, Object... values) {
|| encoding == ASCIIEncoding.INSTANCE) {
valueRope = stringRope;
} else {
valueRope = StringOperations.encodeRope(decodeRope(context, stringRope), UTF8Encoding.INSTANCE);
valueRope = StringOperations.encodeRope(decodeRope(stringRope), UTF8Encoding.INSTANCE);
}
} else if (value instanceof Integer) {
valueRope = new LazyIntRope((int) value);
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ public static abstract class IOOpenPrimitiveNode extends IOPrimitiveArrayArgumen
@TruffleBoundary(throwsControlFlowException = true)
@Specialization(guards = "isRubyString(path)")
public int open(DynamicObject path, int mode, int permission) {
return ensureSuccessful(posix().open(StringOperations.getString(getContext(), path), mode, permission));
return ensureSuccessful(posix().open(StringOperations.getString(path), mode, permission));
}

}
@@ -201,7 +201,7 @@ public static abstract class IOTruncatePrimitiveNode extends IOPrimitiveArrayArg
@TruffleBoundary(throwsControlFlowException = true)
@Specialization(guards = "isRubyString(path)")
public int truncate(DynamicObject path, long length) {
return ensureSuccessful(posix().truncate(StringOperations.getString(getContext(), path), length));
return ensureSuccessful(posix().truncate(StringOperations.getString(path), length));
}

}
@@ -342,7 +342,7 @@ public IOReopenPathPrimitiveNode(RubyContext context, SourceSection sourceSectio
public void performReopenPath(DynamicObject self, DynamicObject path, int mode) {
final int fdSelf = Layouts.IO.getDescriptor(self);
final int newFdSelf;
final String targetPathString = StringOperations.getString(getContext(), path);
final String targetPathString = StringOperations.getString(path);

int fdTarget = ensureSuccessful(posix().open(targetPathString, mode, 0_666));

Original file line number Diff line number Diff line change
@@ -70,9 +70,9 @@ public static DynamicObject createString(RubyContext context, Rope rope) {
}

// Since ByteList.toString does not decode properly
@CompilerDirectives.TruffleBoundary
public static String getString(RubyContext context, DynamicObject string) {
return RopeOperations.decodeRope(context, StringOperations.rope(string));
@TruffleBoundary
public static String getString(DynamicObject string) {
return RopeOperations.decodeRope(StringOperations.rope(string));
}

public static StringCodeRangeableWrapper getCodeRangeableReadWrite(final DynamicObject string) {
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ protected DateTimeZone getTimeZone(VirtualFrame frame) {
if (tz == nil()) {
return DateTimeZone.getDefault();
} else if (RubyGuards.isRubyString(tz)) {
return TimeZoneParser.parse(this, StringOperations.getString(getContext(), (DynamicObject) tz));
return TimeZoneParser.parse(this, StringOperations.getString((DynamicObject) tz));
} else {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ public abstract static class HashPassword extends CoreMethodArrayArgumentsNode {
@Specialization(guards = { "isRubyString(secret)", "isRubyString(salt)" })
public Object hashpw(DynamicObject secret, DynamicObject salt) {
final String result = BCrypt.hashpw(
StringOperations.getString(getContext(), secret),
StringOperations.getString(getContext(), salt));
StringOperations.getString(secret),
StringOperations.getString(salt));
return StringOperations.createString(
getContext(),
StringOperations.createRope(result, USASCIIEncoding.INSTANCE));
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public String toString(DynamicObject object) {
CompilerAsserts.neverPartOfCompilation();

if (RubyGuards.isRubyString(object)) {
return RopeOperations.decodeRope(getContext(), StringOperations.rope(object));
return RopeOperations.decodeRope(StringOperations.rope(object));
} else if (RubyGuards.isRubySymbol(object)) {
return Layouts.SYMBOL.getString(object);
} else if (RubyGuards.isRubyException(object)) {
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ protected Object autoloadConstant(VirtualFrame frame, DynamicObject module, Stri
// We remove it first to allow lookup to ignore it and add it back if there was a failure.
Layouts.MODULE.getFields(constant.getDeclaringModule()).removeConstant(getContext(), this, name);
try {
requireNode.executeRequire(frame, StringOperations.getString(getContext(), path));
requireNode.executeRequire(frame, StringOperations.getString(path));
final RubyConstant resolvedConstant = lookupConstantNode.lookupConstant(frame, module, name);
return executeGetConstant(frame, module, name, resolvedConstant, lookupConstantNode);
} catch (RaiseException e) {
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ public RubyConstant lookupForExistingModule(VirtualFrame frame, String name, Dyn
// call or the recursive execute call.

Layouts.MODULE.getFields(lexicalParent).removeConstant(getContext(), this, name);
getRequireNode().executeRequire(frame, StringOperations.getString(getContext(), (DynamicObject) constant.getValue()));
getRequireNode().executeRequire(frame, StringOperations.getString((DynamicObject) constant.getValue()));
return deepConstantSearch(name, lexicalParent);
}

Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.core.adapaters.OutputStreamAdapter;
import org.jruby.truffle.core.array.ArrayOperations;
import org.jruby.truffle.core.encoding.EncodingManager;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
@@ -143,7 +144,7 @@ public DynamicObject startStream(DynamicObject emitter, int encodingOrdinal) {
}

final Encoding encoding = YAMLEncoding.values()[encodingOrdinal].getEncoding();
final Charset charset = getContext().getEncodingManager().charsetForEncoding(encoding);
final Charset charset = EncodingManager.charsetForEncoding(encoding);

Layouts.PSYCH_EMITTER.setEmitter(emitter,
new Emitter(

0 comments on commit 569ad70

Please sign in to comment.