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

Commits on Jul 31, 2017

  1. Copy the full SHA
    2d650ff View commit details
  2. Copy the full SHA
    5e96dc7 View commit details
  3. Copy the full SHA
    bc2ba39 View commit details
  4. Copy the full SHA
    6a9b771 View commit details
  5. Copy the full SHA
    6279ecf View commit details
  6. Copy the full SHA
    7515105 View commit details
  7. Update jcodings and joni.

    jcodings: new UTF-8 codepoint length logic
    joni: expanded named capture valid strings
    headius committed Jul 31, 2017
    Copy the full SHA
    532edff View commit details
  8. Copy the full SHA
    f0bcc00 View commit details
  9. Copy the full SHA
    11e72ea View commit details
6 changes: 3 additions & 3 deletions core/pom.rb
Original file line number Diff line number Diff line change
@@ -52,12 +52,12 @@
jar 'com.github.jnr:jffi:${jffi.version}'
jar 'com.github.jnr:jffi:${jffi.version}:native'

jar 'org.jruby.joni:joni:2.1.12-SNAPSHOT'
jar 'org.jruby.joni:joni:2.1.12'
jar 'org.jruby.extras:bytelist:1.0.15'
jar 'org.jruby.jcodings:jcodings:1.0.20'
jar 'org.jruby.jcodings:jcodings:1.0.22'
jar 'org.jruby:dirgra:0.3'

jar 'com.headius:invokebinder:1.8-SNAPSHOT'
jar 'com.headius:invokebinder:1.8'
jar 'com.headius:options:1.4'
jar 'com.headius:unsafe-fences:1.0'

4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -173,7 +173,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby.joni</groupId>
<artifactId>joni</artifactId>
<version>2.1.12-SNAPSHOT</version>
<version>2.1.12</version>
</dependency>
<dependency>
<groupId>org.jruby.extras</groupId>
@@ -183,7 +183,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby.jcodings</groupId>
<artifactId>jcodings</artifactId>
<version>1.0.20</version>
<version>1.0.22-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyMatchData.java
Original file line number Diff line number Diff line change
@@ -439,6 +439,7 @@ public RubyArray to_a() {

@JRubyMethod(rest = true)
public IRubyObject values_at(ThreadContext context, IRubyObject[] args) {
check();
Ruby runtime = context.runtime;

RubyArray result = RubyArray.newArray(runtime, args.length);
53 changes: 43 additions & 10 deletions core/src/main/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
import org.jruby.RubyIO;
import org.jruby.RubyInteger;
import org.jruby.RubyKernel;
import org.jruby.RubyModule;
import org.jruby.RubyNumeric;
@@ -47,6 +48,7 @@
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.common.IRubyWarnings;
import org.jruby.java.addons.IOJavaAddons;
import org.jruby.runtime.Block;
import org.jruby.runtime.ObjectAllocator;
@@ -120,6 +122,11 @@ public void setEncoding(Encoding enc) {
ptr.enc = enc;
}

@JRubyMethod(name = "new", rest = true, meta = true)
public static IRubyObject newInstance(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
return RubyIO.newInstance(context, recv, args, block);
}

@JRubyMethod(meta = true, rest = true)
public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
StringIO strio = (StringIO)((RubyClass)recv).newInstance(context, args, Block.NULL_BLOCK);
@@ -1013,9 +1020,32 @@ public IRubyObject truncate(IRubyObject len) {

@JRubyMethod(name = "ungetc")
public IRubyObject ungetc(ThreadContext context, IRubyObject arg) {
// TODO: Not a line-by-line port.
checkReadable();
return ungetbyte(context, arg);
Encoding enc, enc2;

checkModifiable();
if (arg.isNil()) return arg;
if (arg instanceof RubyInteger) {
int len, cc = ((RubyInteger) arg).getIntValue();
byte[] buf = new byte[16];

enc = getEncoding();
len = enc.codeToMbcLength(cc);
if (len <= 0) EncodingUtils.encUintChr(context, cc, enc);
enc.codeToMbc(cc, buf, 0);
ungetbyteCommon(buf, 0, len);
return context.nil;
} else {
arg = arg.convertToString();
enc = getEncoding();
RubyString argStr = (RubyString) arg;
enc2 = argStr.getEncoding();
if (enc != enc2 && enc != ASCIIEncoding.INSTANCE) {
argStr = EncodingUtils.strConvEnc(context, argStr, enc2, enc);
}
ByteList argBytes = argStr.getByteList();
ungetbyteCommon(argBytes.unsafeBytes(), argBytes.begin(), argBytes.realSize());
return context.nil;
}
}

private void ungetbyteCommon(int c) {
@@ -1040,27 +1070,30 @@ private void ungetbyteCommon(int c) {

private void ungetbyteCommon(RubyString ungetBytes) {
ByteList ungetByteList = ungetBytes.getByteList();
int len = ungetByteList.getRealSize();
ungetbyteCommon(ungetByteList.unsafeBytes(), ungetByteList.begin(), ungetByteList.realSize());
}

private void ungetbyteCommon(byte[] ungetBytes, int ungetBegin, int ungetLen) {
final int start; // = ptr.pos;

if (len == 0) return;
if (ungetLen == 0) return;

StringIOData ptr = this.ptr;

synchronized (ptr) {
ptr.string.modify();

if (len > ptr.pos) {
if (ungetLen > ptr.pos) {
start = 0;
} else {
start = ptr.pos - len;
start = ptr.pos - ungetLen;
}

ByteList bytes = ptr.string.getByteList();
ByteList byteList = ptr.string.getByteList();

if (isEndOfString()) bytes.length(Math.max(ptr.pos, len));
if (isEndOfString()) byteList.length(Math.max(ptr.pos, ungetLen));

bytes.replace(start, ptr.pos - start, ungetBytes.getByteList());
byteList.replace(start, ptr.pos - start, ungetBytes, ungetBegin, ungetLen);

ptr.pos = start;
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -620,7 +620,7 @@ private boolean checkAssignmentInCondition(Node node) {
if (node instanceof MultipleAsgnNode || node instanceof LocalAsgnNode || node instanceof DAsgnNode || node instanceof GlobalAsgnNode || node instanceof InstAsgnNode) {
Node valueNode = ((AssignableNode) node).getValueNode();
if (isStaticContent(valueNode)) {
warnings.warn(ID.ASSIGNMENT_IN_CONDITIONAL, node.getPosition(), "found = in conditional, should be ==");
warnings.warn(ID.ASSIGNMENT_IN_CONDITIONAL, lexer.getFile(), lexer.getLineOffset(), "found = in conditional, should be ==");
}
return true;
}
18 changes: 12 additions & 6 deletions core/src/main/java/org/jruby/util/Sprintf.java
Original file line number Diff line number Diff line change
@@ -1564,18 +1564,24 @@ private static int skipSignBits(byte[] bytes, int base) {

private static int round(byte[] bytes, int nDigits, int roundPos, boolean roundDown) {
int next = roundPos + 1;
if (next >= nDigits || bytes[next] < '5' ||
// MRI rounds up on nnn5nnn, but not nnn5 --
// except for when they do
(roundDown && bytes[next] == '5' && next == nDigits - 1)) {
return nDigits;
}
if (next >= nDigits) return nDigits;
if (bytes[next] < '5') return nDigits;
if (roundDown && bytes[next] == '5' && next == nDigits - 1) return nDigits;

if (roundPos < 0) { // "%.0f" % 0.99
System.arraycopy(bytes,0,bytes,1,nDigits);
bytes[0] = '1';
return nDigits + 1;
}
// round half to even
if (roundPos + 1 < nDigits && bytes[roundPos + 1] == '5') {
if ((bytes[roundPos] - '0') % 2 == 0) {
// round down
return nDigits;
}
}
bytes[roundPos] += 1;

while (bytes[roundPos] > '9') {
bytes[roundPos] = '0';
roundPos--;
25 changes: 15 additions & 10 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import org.jcodings.EncodingDB;
import org.jcodings.Ptr;
import org.jcodings.ascii.AsciiTables;
import org.jcodings.exception.ErrorCodes;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF16BEEncoding;
@@ -1992,17 +1993,21 @@ public static IRubyObject ioEncStr(Ruby runtime, IRubyObject str, OpenFile fptr)
public static IRubyObject encUintChr(ThreadContext context, int code, Encoding enc) {
Ruby runtime = context.runtime;

if (!Character.isValidCodePoint(code)) {
// inefficient to create a fixnum for this
return new RubyFixnum(runtime, code).chr(context);
int n;
RubyString str;
switch (n = enc.codeToMbcLength(code)) {
case ErrorCodes.ERR_INVALID_CODE_POINT_VALUE:
throw runtime.newRangeError("invalid codepoint " + Integer.toHexString(code) + " in " + enc);
case ErrorCodes.ERR_TOO_BIG_WIDE_CHAR_VALUE:
case 0:
throw runtime.newRangeError(Integer.toString(code) + " out of char range");
}
str = RubyString.newStringLight(runtime, n);
ByteList strBytes = str.getByteList();
enc.codeToMbc(code, strBytes.unsafeBytes(), strBytes.begin());
if (enc.length(strBytes.unsafeBytes(), strBytes.begin(), strBytes.realSize()) != n) {
throw runtime.newRangeError("invalid codepoint " + Integer.toHexString(code) + " in " + enc);
}

char[] chars = Character.toChars(code);
RubyString str = RubyString.newString(runtime, new String(chars), enc);
// ByteList strByteList = str.getByteList();
// if (StringSupport.preciseLength(enc, strByteList.unsafeBytes(), strByteList.getBegin(), strByteList.getBegin() + strByteList.getRealSize()) != n) {
// rb_raise(rb_eRangeError, "invalid codepoint 0x%X in %s", code, rb_enc_name(enc));
// }
return str;

}