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

Commits on Jul 9, 2015

  1. Copy the full SHA
    05393c3 View commit details
  2. Copy the full SHA
    4ea5001 View commit details
  3. Copy the full SHA
    c4635e3 View commit details
  4. Copy the full SHA
    5006a23 View commit details
  5. Copy the full SHA
    3299e5d View commit details
  6. Extract a local variable to hold the ByteList in StringIO.

    * Use begin() accessor instead of deprecated field.
    eregon committed Jul 9, 2015
    Copy the full SHA
    3912d25 View commit details
  7. Copy the full SHA
    ac5cf32 View commit details
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
@@ -1126,10 +1126,11 @@ public IRubyObject write(ThreadContext context, IRubyObject arg) {

enc = ptr.string.getEncoding();
enc2 = str.getEncoding();
final ByteList strByteList = str.getByteList();
if (enc != enc2 && enc != EncodingUtils.ascii8bitEncoding(runtime)
// this is a hack because we don't seem to handle incoming ASCII-8BIT properly in transcoder
&& enc2 != ASCIIEncoding.INSTANCE) {
str = runtime.newString(EncodingUtils.strConvEnc(context, str.getByteList(), enc2, enc));
str = runtime.newString(EncodingUtils.strConvEnc(context, strByteList, enc2, enc));
}
len = str.size();
if (len == 0) return RubyFixnum.zero(runtime);
@@ -1139,11 +1140,11 @@ public IRubyObject write(ThreadContext context, IRubyObject arg) {
ptr.pos = olen;
}
if (ptr.pos == olen) {
EncodingUtils.encStrBufCat(runtime, ptr.string, str.getByteList(), enc);
EncodingUtils.encStrBufCat(runtime, ptr.string, strByteList, enc);
} else {
strioExtend(ptr.pos, len);
ByteList ptrByteList = ptr.string.getByteList();
System.arraycopy(str.getByteList().getUnsafeBytes(), str.getByteList().getBegin(), ptrByteList.getUnsafeBytes(), ptrByteList.begin + ptr.pos, len);
System.arraycopy(strByteList.getUnsafeBytes(), strByteList.getBegin(), ptrByteList.getUnsafeBytes(), ptrByteList.begin() + ptr.pos, len);
}
ptr.string.infectBy(str);
ptr.string.infectBy(this);
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/kernel/__dir___tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
fails:Kernel#__dir__ returns the name of the directory containing the currently-executing file
fails:Kernel#__dir__ when used in eval with top level binding returns the name of the directory containing the currently-executing file
fails:Kernel#__dir__ returns the real name of the directory containing the currently-executing file
fails:Kernel#__dir__ when used in eval with top level binding returns the real name of the directory containing the currently-executing file
Original file line number Diff line number Diff line change
@@ -1207,8 +1207,8 @@ public RubyBasicObject includedModules(RubyModule module) {

final List<RubyModule> modules = new ArrayList<>();

for (RubyModule included : module.parentAncestors()) {
if (included.isOnlyAModule()) {
for (RubyModule included : module.ancestors()) {
if (included.isOnlyAModule() && included != module) {
modules.add(included);
}
}
Original file line number Diff line number Diff line change
@@ -34,7 +34,9 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;

import jnr.posix.POSIX;

import org.jcodings.Encoding;
import org.jcodings.exception.EncodingException;
import org.jcodings.specific.ASCIIEncoding;
@@ -755,12 +757,14 @@ public ASCIIOnlyNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public boolean asciiOnly(RubyString string) {
if (!getByteList(string).getEncoding().isAsciiCompatible()) {
final ByteList byteList = StringNodes.getByteList(string);

if (!byteList.getEncoding().isAsciiCompatible()) {
return false;
}

for (byte b : getByteList(string).unsafeBytes()) {
if ((b & 0x80) != 0) {
for (int i = 0; i < byteList.length(); i++) {
if ((byteList.get(i) & 0x80) != 0) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -44,7 +44,8 @@ protected static Activation getActivation(RubyBasicObject threadBacktraceLocatio
return (Activation) ACTIVATION_PROPERTY.get(threadBacktraceLocation.getDynamicObject(), true);
}

@CoreMethod(names = "absolute_path")
@CoreMethod(names = { "absolute_path", "path" })
// TODO (eregon, 8 July 2015): these two methods are slightly different (path can be relative if it is the main script)
public abstract static class AbsolutePathNode extends UnaryCoreMethodNode {

public AbsolutePathNode(RubyContext context, SourceSection sourceSection) {
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.Ruby;
import org.jruby.RubyGC;
import org.jruby.ext.rbconfig.RbConfigLibrary;
@@ -35,6 +36,7 @@
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.hash.BucketsStrategy;
import org.jruby.truffle.runtime.subsystems.SimpleShell;
import org.jruby.util.ByteList;
import org.jruby.util.Memo;

import java.util.HashMap;
@@ -196,8 +198,10 @@ public DumpStringNode(RubyContext context, SourceSection sourceSection) {
public RubyBasicObject dumpString(RubyString string) {
final StringBuilder builder = new StringBuilder();

for (byte b : StringNodes.getByteList(string).unsafeBytes()) {
builder.append(String.format("\\x%02x", b));
final ByteList byteList = StringNodes.getByteList(string);

for (int i = 0; i < byteList.length(); i++) {
builder.append(String.format("\\x%02x", byteList.get(i)));
}

return createString(builder.toString());
Original file line number Diff line number Diff line change
@@ -135,8 +135,7 @@ public LocateNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public Object getByte(RubyBasicObject bytes, RubyString pattern, int start, int length) {
final int index = new ByteList(getBytes(bytes).unsafeBytes(), start, length)
.indexOf(StringNodes.getByteList(pattern));
final int index = new ByteList(getBytes(bytes), start, length).indexOf(StringNodes.getByteList(pattern));

if (index == -1) {
return nil();
Original file line number Diff line number Diff line change
@@ -159,7 +159,8 @@ public IOBufferUnshiftPrimitiveNode(RubyContext context, SourceSection sourceSec
public int unshift(VirtualFrame frame, RubyBasicObject ioBuffer, RubyString string, int startPosition) {
setWriteSynced(ioBuffer, false);

int stringSize = StringNodes.getByteList(string).realSize() - startPosition;
final ByteList byteList = StringNodes.getByteList(string);
int stringSize = byteList.realSize() - startPosition;
final int usedSpace = getUsed(ioBuffer);
final int availableSpace = IOBUFFER_SIZE - usedSpace;

@@ -170,7 +171,7 @@ public int unshift(VirtualFrame frame, RubyBasicObject ioBuffer, RubyString stri
ByteList storage = ByteArrayNodes.getBytes(getStorage(ioBuffer));

// Data is copied here - can we do something COW?
System.arraycopy(StringNodes.getByteList(string).unsafeBytes(), startPosition, storage.getUnsafeBytes(), usedSpace, stringSize);
System.arraycopy(byteList.unsafeBytes(), byteList.begin() + startPosition, storage.getUnsafeBytes(), storage.begin() + usedSpace, stringSize);

setUsed(ioBuffer, usedSpace + stringSize);

Original file line number Diff line number Diff line change
@@ -238,7 +238,8 @@ public int truncate(RubyString path, int length) {

@Specialization
public int truncate(RubyString path, long length) {
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
final ByteList byteList = StringNodes.getByteList(path);
final String pathString = RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());
final int result = posix().truncate(pathString, length);
if (result == -1) {
CompilerDirectives.transferToInterpreter();
@@ -469,15 +470,14 @@ public IOWritePrimitiveNode(RubyContext context, SourceSection sourceSection) {
public int write(VirtualFrame frame, RubyBasicObject file, RubyString string) {
final int fd = getDescriptor(file);

final ByteList byteList = StringNodes.getByteList(string);

if (getContext().getDebugStandardOut() != null && fd == STDOUT) {
getContext().getDebugStandardOut().write(StringNodes.getByteList(string).unsafeBytes(), StringNodes.getByteList(string).begin(), StringNodes.getByteList(string).length());
return StringNodes.getByteList(string).length();
getContext().getDebugStandardOut().write(byteList.unsafeBytes(), byteList.begin(), byteList.length());
return byteList.length();
}

// We have to copy here as write starts at byte[0], and the ByteList may not

final ByteList byteList = StringNodes.getByteList(string);

// TODO (eregon, 11 May 2015): review consistency under concurrent modification
final ByteBuffer buffer = ByteBuffer.wrap(byteList.unsafeBytes(), byteList.begin(), byteList.length());

Original file line number Diff line number Diff line change
@@ -12,8 +12,10 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

import jnr.constants.platform.Fcntl;
import jnr.ffi.Pointer;

import org.jruby.RubyEncoding;
import org.jruby.platform.Platform;
import org.jruby.truffle.nodes.core.CoreClass;
@@ -24,6 +26,7 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.ByteList;

import java.nio.charset.StandardCharsets;

@@ -314,7 +317,8 @@ public ReadlinkNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyPointer(pointer)")
public int readlink(RubyString path, RubyBasicObject pointer, int bufsize) {
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
final ByteList byteList = StringNodes.getByteList(path);
final String pathString = RubyEncoding.decodeUTF8(byteList.unsafeBytes(), byteList.begin(), byteList.length());

final int result = posix().readlink(pathString, PointerNodes.getPointer(pointer), bufsize);
if (result == -1) {
@@ -369,7 +373,8 @@ public UnlinkNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int unlink(RubyString path) {
return posix().unlink(RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize()));
final ByteList byteList = StringNodes.getByteList(path);
return posix().unlink(RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize()));
}

}
@@ -397,7 +402,8 @@ public UnsetenvNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyString(name)")
public int unsetenv(RubyBasicObject name) {
final String nameString = RubyEncoding.decodeUTF8(StringNodes.getByteList(name).getUnsafeBytes(), StringNodes.getByteList(name).getBegin(), StringNodes.getByteList(name).getRealSize());
final ByteList byteList = StringNodes.getByteList(name);
final String nameString = RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());

return posix().unsetenv(nameString);
}
@@ -413,7 +419,8 @@ public UtimesNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyPointer(pointer)")
public int utimes(RubyString path, RubyBasicObject pointer) {
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
final ByteList byteList = StringNodes.getByteList(path);
final String pathString = RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());

final int result = posix().utimes(pathString, PointerNodes.getPointer(pointer));
if (result == -1) {
Original file line number Diff line number Diff line change
@@ -13,14 +13,17 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.HiddenKey;
import com.oracle.truffle.api.source.SourceSection;

import jnr.posix.FileStat;

import org.jruby.RubyEncoding;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.ByteList;

public abstract class StatPrimitiveNodes {

@@ -168,7 +171,8 @@ public StatStatPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public int stat(RubyBasicObject rubyStat, RubyString path) {
final FileStat stat = posix().allocateStat();
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());
final ByteList byteList = StringNodes.getByteList(path);
final String pathString = RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());
final int code = posix().stat(pathString, stat);

if (code == 0) {
Original file line number Diff line number Diff line change
@@ -222,21 +222,15 @@ public Object stringByteSubstring(RubyString string, int index, int length) {

final int normalizedIndex = StringNodes.normalizeIndex(string, index);

if (normalizedIndex > bytes.length()) {
if (normalizedIndex < 0 || normalizedIndex > bytes.length()) {
return nil();
}

int rangeEnd = normalizedIndex + length;
if (rangeEnd > bytes.length()) {
rangeEnd = bytes.length();
if (normalizedIndex + length > bytes.length()) {
length = bytes.length() - normalizedIndex;
}

if (normalizedIndex + bytes.begin() < bytes.begin()) {
return nil();
}

final byte[] copiedBytes = Arrays.copyOfRange(bytes.getUnsafeBytes(), normalizedIndex + bytes.begin(), rangeEnd + bytes.begin());
final RubyBasicObject result = StringNodes.createString(string.getLogicalClass(), new ByteList(copiedBytes, bytes.getEncoding()));
final RubyBasicObject result = StringNodes.createString(string.getLogicalClass(), new ByteList(bytes, normalizedIndex, length));

return taintResultNode.maybeTaint(string, result);
}
@@ -306,14 +300,17 @@ public StringCheckNullSafePrimitiveNode(RubyContext context, SourceSection sourc
}

@Specialization
public boolean stringCheckNullSafe(RubyString string) {
for (byte b : StringNodes.getByteList(string).unsafeBytes()) {
if (nullByteProfile.profile(b == 0)) {
return false;
public RubyString stringCheckNullSafe(RubyString string) {
final ByteList byteList = StringNodes.getByteList(string);

for (int i = 0; i < byteList.length(); i++) {
if (nullByteProfile.profile(byteList.get(i) == 0)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("string contains NULL byte", this));
}
}

return true;
return string;
}

}
@@ -470,11 +467,12 @@ public Object stringFindCharacterSingleByte(RubyString string, int offset) {
return nil();
}

if (offset >= StringNodes.getByteList(string).getRealSize()) {
final ByteList byteList = StringNodes.getByteList(string);
if (offset >= byteList.getRealSize()) {
return nil();
}

final RubyBasicObject ret = StringNodes.createString(string.getLogicalClass(), new ByteList(StringNodes.getByteList(string).unsafeBytes(), offset, 1));
final RubyBasicObject ret = StringNodes.createString(string.getLogicalClass(), new ByteList(byteList, offset, 1));

return propagate(string, ret);
}
@@ -487,19 +485,20 @@ public Object stringFindCharacter(RubyString string, int offset) {
return nil();
}

if (offset >= StringNodes.getByteList(string).getRealSize()) {
final ByteList byteList = StringNodes.getByteList(string);
if (offset >= byteList.getRealSize()) {
return nil();
}

final ByteList bytes = StringNodes.getByteList(string);
final ByteList bytes = byteList;
final Encoding enc = bytes.getEncoding();
final int clen = StringSupport.preciseLength(enc, bytes.getUnsafeBytes(), bytes.begin(), bytes.begin() + bytes.realSize());

final RubyBasicObject ret;
if (StringSupport.MBCLEN_CHARFOUND_P(clen)) {
ret = StringNodes.createString(string.getLogicalClass(), new ByteList(StringNodes.getByteList(string).unsafeBytes(), offset, clen));
ret = StringNodes.createString(string.getLogicalClass(), new ByteList(byteList, offset, clen));
} else {
ret = StringNodes.createString(string.getLogicalClass(), new ByteList(StringNodes.getByteList(string).unsafeBytes(), offset, 1));
ret = StringNodes.createString(string.getLogicalClass(), new ByteList(byteList, offset, 1));
}

return propagate(string, ret);
@@ -947,7 +946,8 @@ public RubyBasicObject stringCopyFrom(RubyString string, RubyString other, int s
int dst = dest;
int cnt = size;

int osz = StringNodes.getByteList(other).length();
final ByteList otherBytes = StringNodes.getByteList(other);
int osz = otherBytes.length();
if(src >= osz) return string;
if(cnt < 0) return string;
if(src < 0) src = 0;
@@ -956,12 +956,13 @@ public RubyBasicObject stringCopyFrom(RubyString string, RubyString other, int s
// This bounds checks on the total capacity rather than the virtual
// size() of the String. This allows for string adjustment within
// the capacity without having to change the virtual size first.
int sz = StringNodes.getByteList(string).getUnsafeBytes().length;
final ByteList stringBytes = StringNodes.getByteList(string);
int sz = stringBytes.unsafeBytes().length - stringBytes.begin();
if(dst >= sz) return string;
if(dst < 0) dst = 0;
if(cnt > sz - dst) cnt = sz - dst;

System.arraycopy(StringNodes.getByteList(other).unsafeBytes(), src, StringNodes.getByteList(string).getUnsafeBytes(), dest, cnt);
System.arraycopy(otherBytes.unsafeBytes(), otherBytes.begin() + src, stringBytes.getUnsafeBytes(), stringBytes.begin() + dest, cnt);

return string;
}
@@ -1073,11 +1074,11 @@ public RubyBasicObject stringPattern(RubyClass stringClass, int size, int value)
@Specialization
public RubyBasicObject stringPattern(RubyClass stringClass, int size, RubyString string) {
final byte[] bytes = new byte[size];
final byte[] stringBytes = StringNodes.getByteList(string).unsafeBytes();
final ByteList byteList = StringNodes.getByteList(string);

if (StringNodes.getByteList(string).length() > 0) {
for (int n = 0; n < size; n += StringNodes.getByteList(string).length()) {
System.arraycopy(stringBytes, 0, bytes, n, Math.min(StringNodes.getByteList(string).length(), size - n));
if (byteList.length() > 0) {
for (int n = 0; n < size; n += byteList.length()) {
System.arraycopy(byteList.unsafeBytes(), byteList.begin(), bytes, n, Math.min(byteList.length(), size - n));
}
}

@@ -1271,7 +1272,8 @@ public StringFromByteArrayPrimitiveNode(RubyContext context, SourceSection sourc
@Specialization(guards = "isRubiniusByteArray(bytes)")
public RubyBasicObject stringFromByteArray(RubyBasicObject bytes, int start, int count) {
// Data is copied here - can we do something COW?
return createString(Arrays.copyOfRange(ByteArrayNodes.getBytes(bytes).unsafeBytes(), ByteArrayNodes.getBytes(bytes).begin() + start, ByteArrayNodes.getBytes(bytes).begin() + start + count));
final ByteList byteList = ByteArrayNodes.getBytes(bytes);
return createString(new ByteList(byteList, start, count));
}

}
Original file line number Diff line number Diff line change
@@ -39,9 +39,6 @@ public WriteHexStringNode(RubyContext context, Endianness endianness, int length

@Specialization
public Object write(VirtualFrame frame, ByteList bytes) {
final byte[] b = bytes.unsafeBytes();
int begin = bytes.begin();

int currentByte = 0;

final int lengthToUse;
@@ -58,7 +55,7 @@ public Object write(VirtualFrame frame, ByteList bytes) {
byte currentChar;

if (n < bytes.length()) {
currentChar = b[begin + n];
currentChar = (byte) bytes.get(n);
} else {
currentChar = 0;
}
Original file line number Diff line number Diff line change
@@ -288,9 +288,11 @@ public void prepend(Node currentNode, RubyModule module) {
ModuleChain cur = start;
while (mod != null && !(mod instanceof RubyClass)) {
if (!(mod instanceof PrependMarker)) {
cur.insertAfter(mod.getActualModule());
mod.getActualModule().addDependent(this);
cur = cur.getParentModule();
if (!ModuleOperations.includesModule(this, mod.getActualModule())) {
cur.insertAfter(mod.getActualModule());
mod.getActualModule().addDependent(this);
cur = cur.getParentModule();
}
}
mod = mod.getParentModule();
}
6 changes: 6 additions & 0 deletions truffle/src/main/ruby/core/kernel.rb
Original file line number Diff line number Diff line change
@@ -8,6 +8,12 @@

module Kernel

def __dir__
path = caller_locations(1, 1).first.absolute_path
File.dirname(path)
end
module_function :__dir__

def printf(*args)
print sprintf(*args)
end