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: 788cd5b3f339
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5b44a066d58d
Choose a head ref
  • 14 commits
  • 15 files changed
  • 2 contributors

Commits on Jan 25, 2018

  1. Copy the full SHA
    409f42f View commit details
  2. Copy the full SHA
    9ddcfc0 View commit details
  3. Copy the full SHA
    2685d48 View commit details
  4. Orphan non strict encodings in kcode

    lopex authored and headius committed Jan 25, 2018
    Copy the full SHA
    8d91f9d View commit details
  5. Copy the full SHA
    499e2d9 View commit details
  6. Copy the full SHA
    e959982 View commit details
  7. Copy the full SHA
    ec9adfa View commit details
  8. Patch up some regressions in StringIO/IO#gets stuff.

    * Only gets should set $_.
    * Only StringIO#each/each_line complain about limit=0.
    * Arity-split StringIO#each_line.
    * Remove LAST_LINE frame field requirement from StringIO#each and
      #each_line.
    * Misc tidying.
    headius committed Jan 25, 2018
    Copy the full SHA
    c71b403 View commit details
  9. Copy the full SHA
    49ebdb0 View commit details
  10. Copy the full SHA
    6c5bb4c View commit details
  11. use num2int in StringIO#ungetc

    lopex authored and headius committed Jan 25, 2018
    Copy the full SHA
    a70e62c View commit details
  12. fix IOOBE in test_regexp quote

    lopex authored and headius committed Jan 25, 2018
    Copy the full SHA
    c7e7168 View commit details
  13. use encoding none for n/N option

    lopex authored and headius committed Jan 25, 2018
    Copy the full SHA
    9df4767 View commit details
  14. raise ArgumentError

    lopex authored and headius committed Jan 25, 2018
    Copy the full SHA
    5b44a06 View commit details
4 changes: 2 additions & 2 deletions core/pom.rb
Original file line number Diff line number Diff line change
@@ -52,9 +52,9 @@
jar 'com.github.jnr:jffi:${jffi.version}'
jar 'com.github.jnr:jffi:${jffi.version}:native'

jar 'org.jruby.joni:joni:2.1.13'
jar 'org.jruby.joni:joni:2.1.14'
jar 'org.jruby.extras:bytelist:1.0.15'
jar 'org.jruby.jcodings:jcodings:1.0.18'
jar 'org.jruby.jcodings:jcodings:1.0.27'
jar 'org.jruby:dirgra:0.3'

jar 'com.headius:invokebinder:1.10'
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.13</version>
<version>2.1.14</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.18</version>
<version>1.0.27</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ public static IRubyObject enumeratorize(Ruby runtime, IRubyObject object, String
return new RubyEnumerator(runtime, runtime.getEnumerator(), object, runtime.fastNewSymbol(method), new IRubyObject[] {arg});
}

public static IRubyObject enumeratorize(Ruby runtime, IRubyObject object, String method, IRubyObject[] args) {
public static IRubyObject enumeratorize(Ruby runtime, IRubyObject object, String method, IRubyObject... args) {
return new RubyEnumerator(runtime, runtime.getEnumerator(), object, runtime.fastNewSymbol(method), args); // TODO: make sure it's really safe to not to copy it
}

311 changes: 176 additions & 135 deletions core/src/main/java/org/jruby/RubyIO.java

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/RubyRegexp.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -662,6 +662,10 @@ public static ByteList quote19(ByteList bs, boolean asciiOnly) {
c = bytes[p] & 0xff;
} else {
cl = StringSupport.preciseLength(enc, bytes, p, end);
if (cl < 0) {
p += StringSupport.length(enc, bytes, p, end);
continue;
}
c = enc.mbcToCode(bytes, p, end);
}

@@ -940,8 +944,8 @@ public IRubyObject initialize_m19(IRubyObject arg0, IRubyObject arg1, IRubyObjec

if (!arg2.isNil()) {
ByteList kcodeBytes = arg2.convertToString().getByteList();
if ((kcodeBytes.getRealSize() > 0 && kcodeBytes.getUnsafeBytes()[kcodeBytes.getBegin()] == 'n') ||
(kcodeBytes.getRealSize() > 1 && kcodeBytes.getUnsafeBytes()[kcodeBytes.getBegin() + 1] == 'N')) {
if (kcodeBytes.getRealSize() > 0 && (kcodeBytes.get(0) == 'n' || kcodeBytes.get(0) == 'N')) {
newOptions.setEncodingNone(true);
return regexpInitialize(arg0.convertToString().getByteList(), ASCIIEncoding.INSTANCE, newOptions);
} else {
getRuntime().getWarnings().warn("encoding option is ignored - " + kcodeBytes);
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ast/util/ArgsUtil.java
Original file line number Diff line number Diff line change
@@ -96,6 +96,7 @@ public static IRubyObject getOptionsArg(Ruby runtime, IRubyObject... args) {
}

public static IRubyObject getOptionsArg(Ruby runtime, IRubyObject arg) {
if (arg == null) return runtime.getNil();
return TypeConverter.checkHashType(runtime, arg);
}

460 changes: 281 additions & 179 deletions core/src/main/java/org/jruby/ext/stringio/StringIO.java

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/util/KCode.java
Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@
public enum KCode {
NIL(null, "ASCII", 0),
NONE("NONE", "ASCII", 0),
UTF8("UTF8", "NonStrictUTF8", 64),
SJIS("SJIS", "NonStrictSJIS", 48),
EUC("EUC", "NonStrictEUCJP", 32);
UTF8("UTF8", "UTF8", 64),
SJIS("SJIS", "SJIS", 48),
EUC("EUC", "EUCJP", 32);

private final String kcode;
private final String encodingName;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/RegexpSupport.java
Original file line number Diff line number Diff line change
@@ -469,7 +469,7 @@ private static int unescapeUnicodeBmp(Ruby runtime, ByteList to, byte[] bytes, i
* @param mode error mode
*/
private static void appendUtf8(Ruby runtime, ByteList to, int code, Encoding[] enc, ByteList str, ErrorMode mode) {
checkUnicodeRange(runtime, code, str, mode);
checkUnicodeRange(runtime, code, str, ErrorMode.PREPROCESS);

if (code < 0x80) {
if (to != null) Sprintf.sprintf(runtime, to, "\\x%02X", code);
132 changes: 132 additions & 0 deletions core/src/main/java/org/jruby/util/io/Getline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package org.jruby.util.io;

import org.jcodings.Encoding;
import org.jruby.Ruby;
import org.jruby.RubyString;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.StringSupport;
import org.jruby.util.TypeConverter;

/**
* Encapsulation of the prepare_getline_args logic from MRI, used by StringIO and IO.
*/
public class Getline {
public interface Callback<Self, Return extends IRubyObject> {
Return getline(ThreadContext context, Self self, IRubyObject rs, int limit, boolean chomp, Block block);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io) {
return getlineCall(context, getline, self, enc_io, 0, null, null, null, Block.NULL_BLOCK);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io, IRubyObject arg0) {
return getlineCall(context, getline, self, enc_io, 1, arg0, null, null, Block.NULL_BLOCK);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io, IRubyObject arg0, IRubyObject arg1) {
return getlineCall(context, getline, self, enc_io, 2, arg0, arg1, null, Block.NULL_BLOCK);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return getlineCall(context, getline, self, enc_io, 3, arg0, arg1, arg2, Block.NULL_BLOCK);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io, Block block) {
return getlineCall(context, getline, self, enc_io, 0, null, null, null, block);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io, IRubyObject arg0, Block block) {
return getlineCall(context, getline, self, enc_io, 1, arg0, null, null, block);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io, IRubyObject arg0, IRubyObject arg1, Block block) {
return getlineCall(context, getline, self, enc_io, 2, arg0, arg1, null, block);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return getlineCall(context, getline, self, enc_io, 3, arg0, arg1, arg2, block);
}

public static <Self, Return extends IRubyObject> Return getlineCall(ThreadContext context, Callback<Self, Return> getline, Self self, Encoding enc_io, int argc, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {

boolean chomp = false;
long limit;
IRubyObject opt, optArg = context.nil, sepArg = null, limArg = null;

switch (argc) {
case 1:
optArg = arg0;
break;
case 2:
sepArg = arg0;
optArg = arg1;
break;
case 3:
sepArg = arg0;
limArg = arg1;
optArg = arg2;
}

opt = ArgsUtil.getOptionsArg(context.runtime, optArg);

if (opt.isNil()) {
if (argc == 1) {
sepArg = arg0;
} else if (argc == 2) {
limArg = arg1;
}
} else {
IRubyObject chompKwarg = ArgsUtil.extractKeywordArg(context, "chomp", optArg);
if (chompKwarg != null) {
chomp = chompKwarg.isTrue();
}
}

Ruby runtime = context.runtime;
IRubyObject rs = runtime.getRecordSeparatorVar().get();
IRubyObject lim = context.nil;

if (sepArg != null && limArg == null) { // argc == 1
IRubyObject tmp = context.nil;

if (sepArg.isNil() || !(tmp = TypeConverter.checkStringType(runtime, sepArg)).isNil()) {
rs = tmp;
} else {
lim = sepArg;
}
} else if (sepArg != null && limArg != null) { // argc >= 2
rs = sepArg;
if (!rs.isNil()) {
rs = rs.convertToString();
}
lim = limArg;
}

// properly encode rs
if (!rs.isNil()) {
Encoding enc_rs;

enc_rs = ((RubyString) rs).getEncoding();
if (enc_io != enc_rs &&
(((RubyString) rs).scanForCodeRange() != StringSupport.CR_7BIT ||
(((RubyString) rs).size() > 0 && !enc_io.isAsciiCompatible()))) {
if (rs == runtime.getGlobalVariables().getDefaultSeparator()) {
rs = RubyString.newStringLight(runtime, 0, enc_io);
((RubyString) rs).catAscii(NEWLINE_BYTES, 0, 1);
}
else {
throw runtime.newArgumentError("encoding mismatch: " + enc_io + " IO with " + enc_rs + " RS");
}
}
}

limit = lim.isNil() ? -1 : lim.convertToInteger().getLongValue();

return getline.getline(context, self, rs, (int) limit, chomp, block);
}

private static final byte[] NEWLINE_BYTES = { (byte) '\n' };
}
16 changes: 11 additions & 5 deletions core/src/main/java/org/jruby/util/io/OpenFile.java
Original file line number Diff line number Diff line change
@@ -1556,7 +1556,7 @@ else if (cbuf.capa / 2 < cbuf.off) {
}

// rb_io_getline_fast
public IRubyObject getlineFast(ThreadContext context, Encoding enc, RubyIO io) {
public IRubyObject getlineFast(ThreadContext context, Encoding enc, RubyIO io, boolean chomp) {
Ruby runtime = context.runtime;
IRubyObject str = null;
ByteList strByteList;
@@ -1573,22 +1573,28 @@ public IRubyObject getlineFast(ThreadContext context, Encoding enc, RubyIO io) {
byte[] pBytes = READ_DATA_PENDING_PTR();
int p = READ_DATA_PENDING_OFF();
int e;
int chomplen = 0;

e = memchr(pBytes, p, '\n', pending);
if (e != -1) {
pending = (int) (e - p + 1);
if (chomp) {
chomplen = ((pending > 1 && pBytes[e - 1] == '\r')?1:0) + 1;
}
}
if (str == null) {
str = RubyString.newString(runtime, pBytes, p, pending);
str = RubyString.newString(runtime, pBytes, p, pending - chomplen);
strByteList = ((RubyString) str).getByteList();
rbuf.off += pending;
rbuf.len -= pending;
} else {
((RubyString) str).resize(len + pending);
((RubyString) str).resize(len + pending - chomplen);
strByteList = ((RubyString) str).getByteList();
readBufferedData(strByteList.unsafeBytes(), strByteList.begin() + len, pending);
readBufferedData(strByteList.unsafeBytes(), strByteList.begin() + len, pending - chomplen);
rbuf.off += chomplen;
rbuf.len -= chomplen;
}
len += pending;
len += pending - chomplen;
if (cr != StringSupport.CR_BROKEN)
pos += StringSupport.codeRangeScanRestartable(enc, strByteList.unsafeBytes(), strByteList.begin() + pos, strByteList.begin() + len, cr);
if (e != -1) break;
2 changes: 1 addition & 1 deletion spec/tags/ruby/core/regexp/union_tags.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fails:Regexp.union returns a Regexp with the encoding of multiple non-conflicting ASCII-incompatible String arguments
critical(hangs):Regexp.union returns a Regexp with the encoding of multiple non-conflicting ASCII-incompatible String arguments
4 changes: 0 additions & 4 deletions test/mri/excludes/TestRegexp.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
exclude :test_char_class, "needs investigation"
exclude :test_dup_warn, "needs investigation"
exclude :test_initialize, "needs investigation"
exclude :test_invalid_escape_error, "needs investigation"
exclude :test_invalid_fragment, "needs investigation"
exclude :test_match_without_regexp, "matches non-unicode with exception message using regexp, but our messages are always unicode"
exclude :test_named_capture_nonascii, "needs investigation"
exclude :test_once_multithread, "fails intermittently"
exclude :test_options_in_look_behind, "needs investigation"
exclude :test_raw_hyphen_and_tk_char_type_after_range, "needs investigation"
exclude :test_to_s, "needs investigation"
exclude :test_unescape, "needs investigation"
3 changes: 1 addition & 2 deletions test/mri/excludes/TestString.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exclude :test_rpartition, "needs investigation"
exclude :test_crypt, "does not raise as expected"
exclude :test_rpartition, "needs investigation"
exclude :test_setter, "does not raise as expected"
exclude :test_split_invalid_argument, "raises NoMethodError: undefined method `respond_to?' for #<BasicObject:0x7ff7a4d7>"
1 change: 0 additions & 1 deletion test/mri/excludes/TestSymbol.rb
Original file line number Diff line number Diff line change
@@ -2,4 +2,3 @@
exclude :test_to_proc_arg, "we have plans to do different caching here, see 69662ab8cd1616a2ee076488226a473648fc6267"
exclude :test_to_proc_binding, "needs investigation #4303"
exclude :test_to_proc_iseq, "needs investigation #4303"
exclude :test_symbol_fstr_leak, "assert_no_memory_leak fails due an unexpected nil"