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: 2883be50530a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 48b2185852e3
Choose a head ref

Commits on Mar 13, 2015

  1. Move String#inspect's "actual encoding" logic out and use it.

    This is STR_ENC_GET/get_encoding/get_actual_encoding used in
    several String methods. This fixes issues with the UTF-16/23 dummy
    replicas confusing the transcoding system.
    headius committed Mar 13, 2015
    Copy the full SHA
    8574cb3 View commit details
  2. Fix String#b to force the dup to modify.

    Without modify here, the BINARY encoding gets applied to the
    still-shared ByteList from the original. Caused various issues in
    tests that use #b.
    headius committed Mar 13, 2015
    Copy the full SHA
    f2350fe View commit details
  3. Integer#chr fixes for unusual encodings.

    * Ensure int gets used as unsigned for 32-bit encodings.
    * Double-check resulting character to be sure it is valid.
    headius committed Mar 13, 2015
    Copy the full SHA
    f90bcc9 View commit details
  4. Copy the full SHA
    9717929 View commit details
  5. Copy the full SHA
    3ffcfa9 View commit details

Commits on Mar 19, 2015

  1. Copy the full SHA
    6ee7103 View commit details
  2. Fix error type.

    headius committed Mar 19, 2015
    Copy the full SHA
    6120fca View commit details
  3. Re-port tr logic from MRI.

    headius committed Mar 19, 2015
    Copy the full SHA
    fe821de View commit details
  4. Merge branch 'test-encoding-fixes' into string-quagmire

    Conflicts:
    	core/src/main/java/org/jruby/RubyString.java
    headius committed Mar 19, 2015
    Copy the full SHA
    436dd30 View commit details
  5. Copy the full SHA
    9715da5 View commit details
  6. Copy the full SHA
    f874bb1 View commit details
  7. Wrong base for end.

    headius committed Mar 19, 2015
    Copy the full SHA
    38ade02 View commit details
  8. Base base for position.

    headius committed Mar 19, 2015
    Copy the full SHA
    cc62cf9 View commit details
  9. Copy the full SHA
    a823be5 View commit details
  10. More tweaks for tr.

    headius committed Mar 19, 2015
    Copy the full SHA
    6fa1e10 View commit details

Commits on Mar 20, 2015

  1. Copy the full SHA
    a8a36a7 View commit details
  2. Copy the full SHA
    7f2f4d0 View commit details
  3. Copy the full SHA
    34b5582 View commit details
  4. 2
    Copy the full SHA
    6101605 View commit details
  5. Copy the full SHA
    349f57b View commit details
  6. Copy the full SHA
    4a6ed4b View commit details
  7. Tidy up semantics of matchdata out param in search/match.

    Previously the semantics were a bit of a mix; some consumers
    passed the out param *and* wanted the matchdata set into context,
    some did not want it set, and some did not pass an out param. The
    modified logic always uses *either* context.setBackref *or* the
    out param in all cases.
    
    Methods that use regexp match/search and need matchdata set now
    skip passing the out param, localizing backref setting for those
    methods back to where it should live.
    
    This also fixes matchPos to not require the IRubyObject[] out param
    if the caller is not interested in the coerced string.
    headius committed Mar 20, 2015
    Copy the full SHA
    0c9ebf6 View commit details

Commits on Mar 23, 2015

  1. Copy the full SHA
    802927c View commit details
  2. Copy the full SHA
    78589a9 View commit details
  3. Use MBCLEN "macro" here.

    headius committed Mar 23, 2015
    Copy the full SHA
    911c6c0 View commit details
  4. Copy the full SHA
    b9b728b View commit details
  5. Copy the full SHA
    e8f296a View commit details
  6. Copy the full SHA
    cc3b196 View commit details
  7. Copy the full SHA
    002d38b View commit details
  8. Copy the full SHA
    cf1c6b1 View commit details
  9. Copy the full SHA
    0f3475f View commit details
  10. Tweak port for differing buffer logic.

    I can't see how s could ever == t in the original code, since t
    is set in this block to the address of a new buffer also allocated
    in this block.
    headius committed Mar 23, 2015
    Copy the full SHA
    5de2678 View commit details
  11. Copy the full SHA
    4d9c8c2 View commit details
  12. Copy the full SHA
    1e01d8e View commit details
  13. Explain i == 0 encoding set.

    headius committed Mar 23, 2015
    Copy the full SHA
    861b383 View commit details
  14. Copy the full SHA
    f04e522 View commit details
  15. Copy the full SHA
    f55efaf View commit details

Commits on Mar 24, 2015

  1. Copy the full SHA
    6f1d6e7 View commit details
  2. Copy the full SHA
    dd733e4 View commit details
  3. Unbreak a few items from fixing.

    * Encode ascii codepoints for Array#inspect using target enc.
    * Encoding.prevCodeHead returns -1 for us, since no pointers.
    headius committed Mar 24, 2015
    Copy the full SHA
    cecae9c View commit details
  4. Copy the full SHA
    54d68b1 View commit details
  5. Reduce verbosity.

    headius committed Mar 24, 2015
    Copy the full SHA
    8f973b7 View commit details
  6. Copy the full SHA
    872792d View commit details
  7. Copy the full SHA
    8aa9c0f View commit details
  8. Copy the full SHA
    e9ed3c0 View commit details

Commits on Mar 25, 2015

  1. Copy the full SHA
    d19ab46 View commit details
  2. Copy the full SHA
    87b100f View commit details
  3. Tweaks for String#rindex.

    headius committed Mar 25, 2015
    Copy the full SHA
    44146c4 View commit details
  4. Copy the full SHA
    88f0db2 View commit details

Commits on Mar 26, 2015

  1. Copy the full SHA
    3469f15 View commit details
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.10</version>
<version>3.0.11-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
@@ -138,7 +138,7 @@
<dependency>
<groupId>org.jruby.extras</groupId>
<artifactId>bytelist</artifactId>
<version>1.0.12</version>
<version>1.0.13-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jruby.jcodings</groupId>
15 changes: 8 additions & 7 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@

import org.jcodings.Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF16BEEncoding;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.common.IRubyWarnings.ID;
@@ -1444,15 +1445,15 @@ private IRubyObject inspectAry(ThreadContext context) {
boolean tainted = isTaint();

for (int i = 0; i < realLength; i++) {
if (i > 0) str.cat((byte)',').cat((byte)' ');

RubyString str2 = inspect(context, safeArrayRef(values, begin + i));
if (i == 0 && str2.getEncoding() != encoding) str.setEncoding(str2.getEncoding());
if (str2.isTaint()) tainted = true;

str.cat19(str2);
RubyString s = inspect(context, safeArrayRef(values, begin + i));
if (s.isTaint()) tainted = true;
if (i > 0) str.cat(',', encoding).cat(' ', encoding);
else str.setEncoding(s.getEncoding());

str.cat19(s);
}
str.cat((byte)']');
str.cat(']', encoding);

if (tainted) str.setTaint(true);

17 changes: 12 additions & 5 deletions core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
@@ -348,26 +348,33 @@ public RubyString chr19(ThreadContext context, IRubyObject arg) {
if (enc == ASCIIEncoding.INSTANCE && value >= 0x80) {
return chr19(context);
}
return RubyString.newStringNoCopy(runtime, fromEncodedBytes(runtime, enc, (int)value), enc, 0);
return RubyString.newStringNoCopy(runtime, fromEncodedBytes(runtime, enc, value), enc, 0);
}

private ByteList fromEncodedBytes(Ruby runtime, Encoding enc, int value) {
private ByteList fromEncodedBytes(Ruby runtime, Encoding enc, long value) {
int n;
try {
n = value < 0 ? 0 : enc.codeToMbcLength(value);
n = value < 0 ? 0 : enc.codeToMbcLength((int)value);
} catch (EncodingException ee) {
n = 0;
}

if (n <= 0) throw runtime.newRangeError(this.toString() + " out of char range");

ByteList bytes = new ByteList(n);


boolean ok = false;
try {
enc.codeToMbc(value, bytes.getUnsafeBytes(), 0);
enc.codeToMbc((int)value, bytes.getUnsafeBytes(), 0);
ok = StringSupport.preciseLength(enc, bytes.unsafeBytes(), 0, n) == n;
} catch (EncodingException e) {
// ok = false, fall through
}

if (!ok) {
throw runtime.newRangeError("invalid codepoint " + String.format("0x%x in ", value) + enc.getCharsetName());
}

bytes.setRealSize(n);
return bytes;
}
88 changes: 71 additions & 17 deletions core/src/main/java/org/jruby/RubyMatchData.java
Original file line number Diff line number Diff line change
@@ -138,6 +138,8 @@ private void updatePairs(ByteList value, Encoding encoding, Pair[] pairs) {
}

private void updateCharOffsetOnlyOneReg(ByteList value, Encoding encoding) {
if (charOffsetUpdated) return;

if (charOffsets == null || charOffsets.numRegs < 1) charOffsets = new Region(1);

if (encoding.maxLength() == 1) {
@@ -148,21 +150,32 @@ private void updateCharOffsetOnlyOneReg(ByteList value, Encoding encoding) {
}

Pair[] pairs = new Pair[2];
pairs[0] = new Pair();
pairs[0].bytePos = begin;
pairs[1] = new Pair();
pairs[1].bytePos = end;
if (begin >= 0) {
pairs[0] = new Pair();
pairs[0].bytePos = begin;
pairs[1] = new Pair();
pairs[1].bytePos = end;
}

updatePairs(value, encoding, pairs);

if (begin < 0) {
charOffsets.beg[0] = charOffsets.end[0] = -1;
return;
}
Pair key = new Pair();
key.bytePos = begin;
charOffsets.beg[0] = pairs[Arrays.binarySearch(pairs, key)].charPos;
key.bytePos = end;
charOffsets.end[0] = pairs[Arrays.binarySearch(pairs, key)].charPos;
charOffsets.end[0] = pairs[Arrays.binarySearch(pairs, key)].charPos;

charOffsetUpdated = true;
}

private void updateCharOffsetManyRegs(ByteList value, Encoding encoding) {
if (charOffsetUpdated) return;

final Region regs = this.regs;
int numRegs = regs.numRegs;

if (charOffsets == null || charOffsets.numRegs < numRegs) charOffsets = new Region(numRegs);
@@ -172,6 +185,7 @@ private void updateCharOffsetManyRegs(ByteList value, Encoding encoding) {
charOffsets.beg[i] = regs.beg[i];
charOffsets.end[i] = regs.end[i];
}
charOffsetUpdated = true;
return;
}

@@ -197,7 +211,9 @@ private void updateCharOffsetManyRegs(ByteList value, Encoding encoding) {
charOffsets.beg[i] = pairs[Arrays.binarySearch(pairs, key)].charPos;
key.bytePos = regs.end[i];
charOffsets.end[i] = pairs[Arrays.binarySearch(pairs, key)].charPos;
}
}

charOffsetUpdated = true;
}

private void updateCharOffset() {
@@ -454,28 +470,27 @@ public IRubyObject size(ThreadContext context) {
return regs == null ? RubyFixnum.one(runtime) : RubyFixnum.newFixnum(runtime, regs.numRegs);
}

/** match_begin
*
/**
* MRI: match_begin
*/
@JRubyMethod
public IRubyObject begin(ThreadContext context, IRubyObject index) {
check();
Ruby runtime = context.runtime;

int i = backrefNumber(index);
Ruby runtime = context.runtime;

if (i < 0 || (regs == null ? 1 : regs.numRegs) <= i) throw runtime.newIndexError("index " + i + " out of matches");
check();
if (i < 0 || (regs == null ? 1 : regs.numRegs) <= i) {
throw runtime.newIndexError("index " + i + " out of matches");
}

int b = regs == null ? begin : regs.beg[i];

if (b < 0) return runtime.getNil();
if (b < 0) return context.nil;

if (!str.singleByteOptimizable()) {
updateCharOffset();
b = charOffsets.beg[i];
}
updateCharOffset();

return RubyFixnum.newFixnum(runtime, b);
return RubyFixnum.newFixnum(runtime, charOffsets.beg[i]);
}

/** match_end
@@ -627,4 +642,43 @@ public RubyFixnum hash() {
return getRuntime().newFixnum(pattern.hashCode() ^ str.hashCode());
}

/**
* Get the begin offset of the given region, or -1 if the region does not exist.
*
* @param i the region for which to fetch the begin offset
* @return the begin offset for the region
*/
public int begin(int i) {
if (regs == null) {
if (i > 1) return -1;
return begin;
}
if (i > regs.numRegs) return -1;
return regs.beg[i];
}

/**
* Get the end offset of the given region, or -1 if the region does not exist.
*
* @param i the region for which to fetch the end offset
* @return the end offset for the region
*/
public int end(int i) {
if (regs == null) {
if (i > 1) return -1;
return end;
}
if (i > regs.numRegs) return -1;
return regs.end[i];
}

/**
* Fetch the number of regions in this match.
*
* @return the number of regions in this match
*/
public int numRegs() {
return regs == null ? 1 : regs.numRegs;
}

}
15 changes: 14 additions & 1 deletion core/src/main/java/org/jruby/RubyObject.java
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
import java.util.List;
import java.util.Set;

import org.jcodings.Encoding;
import org.jruby.anno.JRubyClass;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.Block;
@@ -530,7 +531,19 @@ private int nonFixnumHashCode(IRubyObject hashValue) {
* Prefered over callMethod(context, "inspect")
*/
public static RubyString inspect(ThreadContext context, IRubyObject object) {
return RubyString.objAsString(context, object.callMethod(context, "inspect"));
Ruby runtime = context.runtime;
RubyString str = RubyString.objAsString(context, object.callMethod(context, "inspect"));
Encoding ext = runtime.getDefaultExternalEncoding();
if (!ext.isAsciiCompatible()) {
if (!str.isAsciiOnly()) {
throw runtime.newEncodingCompatibilityError("inspected result must be ASCII only if default external encoding is ASCII incompatible");
}
return str;
}
if (str.getEncoding() != ext && !str.isAsciiOnly()) {
throw runtime.newEncodingCompatibilityError("inspected result must be ASCII only or use the default external encoding");
}
return str;
}

/**
Loading