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

Commits on Apr 24, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    ad73ff4 View commit details
  2. Split String[] limit test to separate method and exclude.

    JRuby's limits for string offset are within int range, so this is
    clearly supposed to be a range error for us (rather than an index
    error) since the requested index is well outside int range.
    headius committed Apr 24, 2018
    Copy the full SHA
    b75be84 View commit details
  3. Copy the full SHA
    796b958 View commit details
  4. Copy the full SHA
    8780600 View commit details
  5. Copy the full SHA
    80a3e1b View commit details
  6. Deprecation.

    headius committed Apr 24, 2018
    Copy the full SHA
    d56fca0 View commit details
  7. Copy the full SHA
    c90308b View commit details
  8. Copy the full SHA
    a44cdc8 View commit details
  9. Copy the full SHA
    74538c4 View commit details
  10. Copy the full SHA
    c09b063 View commit details
  11. Copy the full SHA
    91b3a8d View commit details
  12. Copy the full SHA
    2da9f75 View commit details

Commits on Apr 25, 2018

  1. Copy the full SHA
    a9aa369 View commit details
  2. Copy the full SHA
    50ba1a4 View commit details
  3. Actually bind Exception#full_message and add kwarg logic.

    Note: we do not have reversed traces yet.
    headius committed Apr 25, 2018
    Copy the full SHA
    225be09 View commit details
  4. Copy the full SHA
    5443d09 View commit details
  5. Copy the full SHA
    18849e2 View commit details
  6. Copy the full SHA
    cf66ceb View commit details
  7. Copy the full SHA
    f393ef1 View commit details
  8. Copy the full SHA
    6746915 View commit details
  9. Dispatch logic change for respond_to_missing?-methods.

    This appears to be a 2.5 change. If respond_to_missing? indicates
    a missing method would be handled by method_missing, then #method
    should return a callable object that always calls through
    method_missing.
    headius committed Apr 25, 2018
    Copy the full SHA
    516b4c3 View commit details
  10. Copy the full SHA
    43d5002 View commit details
  11. Copy the full SHA
    a21440b View commit details
  12. Revert "Reapply 5441086 lost in later compiler optz commit."

    This reverts commit 18849e2.
    headius committed Apr 25, 2018
    Copy the full SHA
    5a8d17b View commit details
  13. [noci] Update comment

    enebo committed Apr 25, 2018
    Copy the full SHA
    b9dd399 View commit details
  14. Copy the full SHA
    bbba978 View commit details
  15. Address a couple of comments from PR and change some obvious RubySymbol

    consumers to proper method instead of toString.  This also addressed some
    more m17n errors we had.
    enebo committed Apr 25, 2018
    Copy the full SHA
    ad79660 View commit details
  16. Copy the full SHA
    e1f6790 View commit details
Showing with 425 additions and 254 deletions.
  1. +5 −2 core/src/main/java/org/jruby/BasicObjectStub.java
  2. +14 −8 core/src/main/java/org/jruby/RubyBasicObject.java
  3. +2 −2 core/src/main/java/org/jruby/RubyConverter.java
  4. +36 −0 core/src/main/java/org/jruby/RubyException.java
  5. +64 −48 core/src/main/java/org/jruby/RubyFloat.java
  6. +111 −41 core/src/main/java/org/jruby/RubyIO.java
  7. +1 −1 core/src/main/java/org/jruby/RubyInteger.java
  8. +1 −1 core/src/main/java/org/jruby/RubyKernel.java
  9. +11 −13 core/src/main/java/org/jruby/RubyModule.java
  10. +9 −6 core/src/main/java/org/jruby/RubyString.java
  11. +1 −2 core/src/main/java/org/jruby/RubyStruct.java
  12. +9 −3 core/src/main/java/org/jruby/RubySymbol.java
  13. +1 −1 core/src/main/java/org/jruby/ast/OpAsgnNode.java
  14. +1 −1 core/src/main/java/org/jruby/ext/io/wait/IOWaitLibrary.java
  15. +2 −2 core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java
  16. +12 −10 core/src/main/java/org/jruby/ext/stringio/StringIO.java
  17. +8 −3 core/src/main/java/org/jruby/ir/IRBuilder.java
  18. +1 −2 core/src/main/java/org/jruby/ir/instructions/RaiseRequiredKeywordArgumentError.java
  19. +1 −1 core/src/main/java/org/jruby/ir/persistence/IRDumper.java
  20. +14 −10 core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
  21. +1 −1 core/src/main/java/org/jruby/runtime/JavaSites.java
  22. +1 −1 core/src/main/java/org/jruby/runtime/backtrace/TraceType.java
  23. +104 −80 core/src/main/java/org/jruby/util/StringSupport.java
  24. +5 −5 core/src/main/java/org/jruby/util/io/PopenExecutor.java
  25. +2 −0 lib/ruby/stdlib/rbconfig/sizeof.rb
  26. +0 −10 spec/ruby/core/dir/glob_spec.rb
  27. +1 −0 spec/tags/ruby/core/module/prepend_tags.txt
  28. +2 −0 test/mri/excludes/TestException.rb
  29. +2 −0 test/mri/excludes/TestIO.rb
  30. +1 −0 test/mri/excludes/TestString.rb
  31. +2 −0 test/mri/ruby/test_string.rb
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/BasicObjectStub.java
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@

import static org.jruby.runtime.invokedynamic.MethodNames.INSPECT;
import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.util.RubyStringBuilder.str;

import org.jruby.util.TypeConverter;

public final class BasicObjectStub {
@@ -146,8 +148,9 @@ public static Class getJavaClass(IRubyObject self) {

public static String asJavaString(IRubyObject self) {
IRubyObject asString = checkStringType(self);
if(!asString.isNil()) return ((RubyString)asString).asJavaString();
throw getRuntime(self).newTypeError(inspect(self).toString() + " is not a string");
if(!asString.isNil()) return asString.asJavaString();
Ruby runtime = getRuntime(self);
throw runtime.newTypeError(str(runtime, "", inspect(self), " is not a string"));
}

public static RubyString asString(IRubyObject self) {
22 changes: 14 additions & 8 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -809,13 +809,19 @@ public IRubyObject anyToString() {
Ruby runtime = getRuntime();

/* 6:tags 16:addr 1:eos */
RubyString bytes = runtime.newString("#<");
bytes.cat(getMetaClass().getRealClass().toRubyString(runtime.getCurrentContext()));
bytes.catString(":0x");
bytes.catString(Integer.toHexString(System.identityHashCode(this)));
bytes.catString(">");
bytes.setTaint(isTaint());
return bytes;
String hex = Integer.toHexString(System.identityHashCode(this));
ByteList className = getMetaClass().getRealClass().toRubyString(runtime.getCurrentContext()).getByteList();
ByteList bytes = new ByteList(2 + className.realSize() + 3 + hex.length() + 1);
bytes.setEncoding(className.getEncoding());
bytes.append('#').append('<');
bytes.append(className);
bytes.append(':').append('0').append('x');
bytes.append(hex.getBytes());
bytes.append('>');

RubyString str = RubyString.newString(runtime, bytes);
str.setTaint(isTaint());
return str;
}

/**
@@ -2533,7 +2539,7 @@ public IRubyObject singleton_method(IRubyObject name) {
*/
public IRubyObject method(IRubyObject name) {
final RubySymbol symbol = TypeConverter.checkID(name);
return getMetaClass().newMethod(this, symbol.asJavaString(), true, null, true);
return getMetaClass().newMethod(this, symbol.idString(), true, null, true);
}

@Deprecated
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyConverter.java
Original file line number Diff line number Diff line change
@@ -380,7 +380,7 @@ public IRubyObject convert(ThreadContext context, IRubyObject srcBuffer) {

if (ret instanceof RubySymbol) {
RubySymbol retSym = (RubySymbol)ret;
String retStr = retSym.toString();
String retStr = retSym.asJavaString(); // 7bit comparison

if (retStr.equals(EConvResult.InvalidByteSequence.symbolicName()) ||
retStr.equals(EConvResult.UndefinedConversion.symbolicName()) ||
@@ -419,7 +419,7 @@ public IRubyObject finish(ThreadContext context) {

if (ret instanceof RubySymbol) {
RubySymbol retSym = (RubySymbol)ret;
String retStr = retSym.toString();
String retStr = retSym.asJavaString(); // 7 bit comparison

if (retStr.equals(EConvResult.InvalidByteSequence.symbolicName()) ||
retStr.equals(EConvResult.UndefinedConversion.symbolicName()) ||
36 changes: 36 additions & 0 deletions core/src/main/java/org/jruby/RubyException.java
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@

import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.exceptions.Exception;
import org.jruby.exceptions.JumpException.FlowControlException;
import org.jruby.exceptions.RaiseException;
@@ -52,6 +53,7 @@
import org.jruby.runtime.component.VariableEntry;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.util.TypeConverter;

import java.io.IOException;
import java.io.PrintStream;
@@ -69,6 +71,7 @@ public class RubyException extends RubyObject {
public static final int TRACE_HEAD = 8;
public static final int TRACE_TAIL = 4;
public static final int TRACE_MAX = RubyException.TRACE_HEAD + RubyException.TRACE_TAIL + 6;
public static final String[] FULL_MESSAGE_KEYS = {"highlight", "order"};
protected BacktraceData backtraceData;
IRubyObject message;
// We initialize this to UNDEF to know whether cause has been initialized (from ruby space we will just see nil
@@ -174,10 +177,43 @@ public static IRubyObject newException(ThreadContext context, RubyClass exceptio
return exceptionClass.callMethod(context, "new", message.convertToString());
}

@JRubyMethod
public IRubyObject full_message(ThreadContext context) {
return RubyString.newString(context.runtime, TraceType.Format.MRI.printBacktrace(this, false));
}

@JRubyMethod
public IRubyObject full_message(ThreadContext context, IRubyObject opts) {
Ruby runtime = context.runtime;
IRubyObject optArg = ArgsUtil.getOptionsArg(runtime, opts);
boolean highlight = false;
boolean reverse = false;

if (!optArg.isNil()) {
IRubyObject[] highlightOrder = ArgsUtil.extractKeywordArgs(context, (RubyHash) optArg, FULL_MESSAGE_KEYS);

IRubyObject vHigh = highlightOrder[0];
if (vHigh == UNDEF) vHigh = context.nil;
if (vHigh != context.nil && vHigh != context.fals && vHigh != context.tru) {
throw runtime.newArgumentError("expected true or false as highlight: " + vHigh);
}
highlight = vHigh.isTrue();

IRubyObject vOrder = highlightOrder[1];
if (vOrder != UNDEF) {
vOrder = TypeConverter.checkID(vOrder);
if (vOrder == runtime.newSymbol("bottom")) reverse = true;
else if (vOrder == runtime.newSymbol("top")) reverse = false;
else {
throw runtime.newArgumentError("expected :top or :bottom as order: " + vOrder);
}
}
}

// TODO: reverse
return RubyString.newString(runtime, TraceType.Format.MRI.printBacktrace(this, highlight));
}

@JRubyMethod(optional = 2, visibility = PRIVATE)
public IRubyObject initialize(IRubyObject[] args, Block block) {
if ( args.length == 1 ) setMessage(args[0]);
112 changes: 64 additions & 48 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@

package org.jruby;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Locale;
@@ -48,7 +47,6 @@
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.runtime.Arity;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.JavaSites.FloatSites;
import org.jruby.runtime.ObjectAllocator;
@@ -63,7 +61,6 @@
import static org.jruby.util.Numeric.f_abs;
import static org.jruby.util.Numeric.f_add;
import static org.jruby.util.Numeric.f_expt;
import static org.jruby.util.Numeric.f_lshift;
import static org.jruby.util.Numeric.f_mul;
import static org.jruby.util.Numeric.f_negate;
import static org.jruby.util.Numeric.f_negative_p;
@@ -90,6 +87,7 @@ public class RubyFloat extends RubyNumeric {
public static final double EPSILON = 2.2204460492503131e-16;
public static final double INFINITY = Double.POSITIVE_INFINITY;
public static final double NAN = Double.NaN;
public static final int FLOAT_DIG = DIG + 2;

public static RubyClass createFloatClass(Ruby runtime) {
RubyClass floatc = runtime.defineClass("Float", runtime.getNumeric(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
@@ -855,26 +853,32 @@ public IRubyObject floor(ThreadContext context, IRubyObject digits) {
return ((RubyInteger) truncate(context)).floor(context, digits);
}

Ruby runtime = context.runtime;
number = value;

if (number == 0.0) {
return ndigits > 0 ? this : RubyFixnum.zero(runtime);
}

if (ndigits > 0) {
RubyNumeric[] num = {this};
Ruby runtime = context.runtime;
if (floatInvariantRound(runtime, number, ndigits, num)) return num[0];
long[] binexp = {0};
frexp(number, binexp);
if (floatRoundOverflow(ndigits, binexp)) return num[0];
if (number > 0.0 && floatRoundUnderflow(ndigits, binexp))
return newFloat(runtime, 0.0);
f = Math.pow(10, ndigits);
f = Math.floor(number * f) / f;
return dbl2num(runtime, f);
} else {
RubyInteger num = dbl2ival(runtime, Math.floor(number));
if (ndigits < 0) num = (RubyInteger) num.floor(context, digits);
return num;
}

return floor(context);
}

// MRI: float_invariant_round
private static boolean floatInvariantRound(Ruby runtime, double number, int ndigits, RubyNumeric[] num) {
int float_dig = DIG+2;
long[] binexp = {0L};

frexp(number, binexp);
// MRI: float_round_overflow
private static boolean floatRoundOverflow(int ndigits, long[] binexp) {

/* Let `exp` be such that `number` is written as:"0.#{digits}e#{exp}",
i.e. such that 10 ** (exp - 1) <= |number| < 10 ** exp
@@ -894,13 +898,16 @@ private static boolean floatInvariantRound(Ruby runtime, double number, int ndig
If ndigits + ceil(binexp/(3 or 4)) < 0 the result is 0
*/

if (Double.isInfinite(number) || Double.isNaN(number) ||
(ndigits >= float_dig - (binexp[0] > 0 ? binexp[0] / 4 : binexp[0] / 3 - 1))) {
if (ndigits >= FLOAT_DIG - (binexp[0] > 0 ? binexp[0] / 4 : binexp[0] / 3 - 1)) {
return true;
}

return false;
}

// MRI: float_round_underflow
private static boolean floatRoundUnderflow(int ndigits, long[] binexp) {
if (ndigits < - (binexp[0] > 0 ? binexp[0] / 3 + 1 : binexp[0] / 4)) {
num[0] = RubyFixnum.zero(runtime);
return true;
}

@@ -928,20 +935,25 @@ public IRubyObject ceil(ThreadContext context, IRubyObject digits) {

number = value;

if (ndigits < 0) {
return ((RubyInteger) dbl2ival(runtime, Math.ceil(number))).ceil(context, digits);
if (number == 0.0) {
return ndigits > 0 ? this : RubyFixnum.zero(runtime);
}

if (ndigits == 0) {
return dbl2ival(runtime, Math.ceil(number));
if (ndigits > 0) {
long[] binexp = {0};
frexp(number, binexp);
if (floatRoundOverflow(ndigits, binexp)) return this;
if (number < 0.0 && floatRoundUnderflow(ndigits, binexp))
return newFloat(runtime, 0.0);
f = Math.pow(10, ndigits);
f = Math.ceil(number * f) / f;
return newFloat(runtime, f);
}
else {
IRubyObject num = dbl2ival(runtime, Math.ceil(number));
if (ndigits < 0) num = ((RubyInteger) num).ceil(context, digits);
return num;
}

RubyNumeric[] num = {this};
if (floatInvariantRound(runtime, number, ndigits, num)) return num[0];

f = Math.pow(10, ndigits);

return RubyFloat.newFloat(runtime, Math.ceil(number * f) / f);
}

/**
@@ -950,7 +962,7 @@ public IRubyObject ceil(ThreadContext context, IRubyObject digits) {
@Override
@JRubyMethod(name = "round")
public IRubyObject round(ThreadContext context) {
return roundShared(context, RoundingMode.HALF_UP, 0);
return roundShared(context, 0, RoundingMode.HALF_UP);
}

/**
@@ -969,7 +981,7 @@ public IRubyObject round(ThreadContext context, IRubyObject arg0) {

RoundingMode roundingMode = getRoundingMode(context, opts);

return roundShared(context, roundingMode, digits);
return roundShared(context, digits, roundingMode);
}

/**
@@ -986,35 +998,39 @@ public IRubyObject round(ThreadContext context, IRubyObject _digits, IRubyObject

RoundingMode roundingMode = getRoundingMode(context, opts);

return roundShared(context, roundingMode, digits);
return roundShared(context, digits, roundingMode);
}

private IRubyObject roundShared(ThreadContext context, RoundingMode roundingMode, int ndigits) {
/*
* MRI: flo_round main body
*/
public IRubyObject roundShared(ThreadContext context, int ndigits, RoundingMode mode) {
Ruby runtime = context.runtime;
double number, f, x;

if (Double.isInfinite(value)) {
if (ndigits <= 0) throw context.runtime.newFloatDomainError(value < 0 ? "-Infinity" : "Infinity");
return this;
}
number = value;

if (Double.isNaN(value)) {
if (ndigits <= 0) throw context.runtime.newFloatDomainError("NaN");
return this;
if (number == 0.0) {
return ndigits > 0 ? this : RubyFixnum.zero(runtime);
}

if (ndigits < 0) {
return ((RubyInteger) truncate(context)).round(context, ndigits);
return ((RubyInteger) to_int(context)).roundShared(context, ndigits, mode);
}
number = value;
if (ndigits == 0) {
x = doRound(context, roundingMode, number, 1.0);
return dbl2ival(context.runtime, x);
x = doRound(context, mode, number, 1.0);
return dbl2ival(runtime, x);
}
RubyNumeric[] num = {this};
if (floatInvariantRound(context.runtime, number, ndigits, num)) return num[0];
f = Math.pow(10, ndigits);
x = doRound(context, roundingMode, number, f);
return dbl2num(context.runtime, x / f);
if (Double.isFinite(value)) {
long[] binexp = {0};
frexp(number, binexp);
if (floatRoundOverflow(ndigits, binexp)) return this;
if (floatRoundUnderflow(ndigits, binexp)) return newFloat(runtime, 0);
f = Math.pow(10, ndigits);
x = doRound(context, mode, number, f);
return newFloat(runtime, x / f);
}

return this;
}

private static double doRound(ThreadContext context, RoundingMode roundingMode, double number, double scale) {
Loading