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

Commits on Jul 4, 2017

  1. Copy the full SHA
    61041af View commit details
  2. Copy the full SHA
    8cd241d View commit details
  3. Copy the full SHA
    44a793a View commit details
  4. Copy the full SHA
    9d3df1c View commit details
  5. Copy the full SHA
    948e0f9 View commit details
  6. Copy the full SHA
    54ad3c2 View commit details
  7. cleanup ConvertBytes - remove is19 field and deprecate method19

    ... also internally renamed some of the fields for better readability
    kares committed Jul 4, 2017
    Copy the full SHA
    a69e4ce View commit details
  8. Copy the full SHA
    5e13444 View commit details
  9. Copy the full SHA
    bed04bb View commit details
  10. Copy the full SHA
    5e779b5 View commit details
  11. Copy the full SHA
    7bc2809 View commit details
  12. Copy the full SHA
    d0d8e67 View commit details
  13. Copy the full SHA
    8cb3c27 View commit details
  14. cleanup BigDecimal from the dual 1.8/1.9 Ruby support heritage

    + refactored/simplified div/quo implementation - was hard to manage
    kares committed Jul 4, 2017
    Copy the full SHA
    97e357c View commit details
  15. Copy the full SHA
    5cbe020 View commit details
  16. Copy the full SHA
    4d30cb8 View commit details
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -3684,7 +3684,7 @@ public IRubyObject product(ThreadContext context, IRubyObject[] args, Block bloc
arrays[0] = this;
RubyClass array = runtime.getArray();
JavaSites.CheckedSites to_ary_checked = sites(context).to_ary_checked;
for (int i = 1; i < n; i++) arrays[i] = (RubyArray) TypeConverter.convertToType19(context, args[i - 1], array, to_ary_checked);
for (int i = 1; i < n; i++) arrays[i] = (RubyArray) TypeConverter.convertToType(context, args[i - 1], array, to_ary_checked);

int resultLen = 1;
for (int i = 0; i < n; i++) {
@@ -4391,7 +4391,7 @@ public static IRubyObject try_convert(ThreadContext context, IRubyObject self, I
public RubyString pack(ThreadContext context, IRubyObject obj) {
RubyString iFmt = obj.convertToString();
try {
return Pack.pack(context, context.runtime, this, iFmt);
return Pack.pack(context, this, iFmt);
} catch (ArrayIndexOutOfBoundsException e) {
throw concurrentModification(context.runtime, e);
}
8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -745,7 +745,9 @@ public RubyInteger convertToInteger() {

IRubyObject result = TypeConverter.convertToType(context, this, runtime.getInteger(), sites.to_int_checked, true);

if (!(result instanceof RubyInteger)) throw getRuntime().newTypeError(getMetaClass().getName() + "#to_int should return Integer");
if (!(result instanceof RubyInteger)) {
throw getRuntime().newTypeError(getMetaClass().getName() + "#to_int should return Integer");
}

return (RubyInteger) result;
}
@@ -768,7 +770,9 @@ public RubyInteger convertToInteger(String convertMethod) {
result = TypeConverter.convertToType(this, getRuntime().getInteger(), convertMethod, true);
}

if (!(result instanceof RubyInteger)) throw getRuntime().newTypeError(getMetaClass().getName() + "#to_int should return Integer");
if (!(result instanceof RubyInteger)) {
throw getRuntime().newTypeError(getMetaClass().getName() + '#' + convertMethod + " should return Integer");
}

return (RubyInteger) result;
}
150 changes: 70 additions & 80 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -374,18 +374,21 @@ private IRubyObject subtractOther(ThreadContext context, IRubyObject other) {
/** rb_big_mul
*
*/
public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
return op_mul19(context, other);
}

@JRubyMethod(name = "*", required = 1)
public IRubyObject op_mul19(ThreadContext context, IRubyObject other) {
public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
if (other instanceof RubyFixnum) {
return bignorm(runtime, value.multiply(fix2big(((RubyFixnum) other))));
} else if (other instanceof RubyBignum) {
return bignorm(runtime, value.multiply(((RubyBignum)other).value));
} else return opMulOther(context, other);
}
if (other instanceof RubyBignum) {
return bignorm(runtime, value.multiply(((RubyBignum) other).value));
}
return opMulOther(context, other);
}

@Deprecated
public final IRubyObject op_mul19(ThreadContext context, IRubyObject other) {
return op_mul(context, other);
}

public IRubyObject op_mul(ThreadContext context, long other) {
@@ -457,15 +460,19 @@ public IRubyObject op_idiv(ThreadContext context, IRubyObject other) {
/** rb_big_divmod
*
*/
@Override
@JRubyMethod(name = "divmod", required = 1)
public IRubyObject divmod(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;

final BigInteger otherValue;
if (other instanceof RubyFixnum) {
otherValue = fix2big((RubyFixnum) other);
} else if (other instanceof RubyBignum) {
otherValue = ((RubyBignum) other).value;
} else {
if (other instanceof RubyFloat && ((RubyFloat)other).getDoubleValue() == 0) {
throw runtime.newZeroDivisionError();
}
return coerceBin(context, sites(context).divmod, other);
}

@@ -479,124 +486,87 @@ public IRubyObject divmod(ThreadContext context, IRubyObject other) {
return RubyArray.newArray(runtime, bignorm(runtime, results[0]), bignorm(runtime, results[1]));
}

@JRubyMethod(name = "divmod", required = 1)
public IRubyObject divmod19(ThreadContext context, IRubyObject other) {
if (!other.isNil() && other instanceof RubyFloat
&& ((RubyFloat)other).getDoubleValue() == 0) {
throw context.runtime.newZeroDivisionError();
}
return divmod(context, other);
}

/** rb_big_modulo
*
*/
@JRubyMethod(name = {"%", "modulo"}, required = 1)
public IRubyObject op_mod(ThreadContext context, IRubyObject other) {
final BigInteger otherValue;
if (other instanceof RubyFixnum) {
otherValue = fix2big((RubyFixnum) other);
} else if (other instanceof RubyBignum) {
otherValue = ((RubyBignum) other).value;
} else {
if (other instanceof RubyFloat && ((RubyFloat) other).getDoubleValue() == 0) {
throw context.runtime.newZeroDivisionError();
}
return coerceBin(context, sites(context).op_mod, other);
}
Ruby runtime = context.runtime;
if (otherValue.signum() == 0) throw runtime.newZeroDivisionError();

if (otherValue.signum() == 0) throw context.runtime.newZeroDivisionError();

BigInteger result = value.mod(otherValue.abs());
if (otherValue.signum() == -1 && result.signum() != 0) result = otherValue.add(result);
return bignorm(runtime, result);
return bignorm(context.runtime, result);
}

/** rb_big_modulo
*
*/
@JRubyMethod(name = {"%", "modulo"}, required = 1)
@Deprecated
public IRubyObject op_mod19(ThreadContext context, IRubyObject other) {
if (!other.isNil() && other instanceof RubyFloat
&& ((RubyFloat)other).getDoubleValue() == 0) {
throw context.runtime.newZeroDivisionError();
}
return op_mod(context, other);
}

/** rb_big_remainder
*
*/
@Override
@JRubyMethod(name = "remainder", required = 1)
public IRubyObject remainder(ThreadContext context, IRubyObject other) {
final BigInteger otherValue;
if (other instanceof RubyFixnum) {
otherValue = fix2big(((RubyFixnum) other));
} else if (other instanceof RubyBignum) {
otherValue = ((RubyBignum) other).value;
} else {
if (other instanceof RubyFloat && ((RubyFloat) other).getDoubleValue() == 0) {
throw context.runtime.newZeroDivisionError();
}
return coerceBin(context, sites(context).remainder, other);
}
Ruby runtime = context.runtime;
if (otherValue.signum() == 0) throw runtime.newZeroDivisionError();
return bignorm(runtime, value.remainder(otherValue));
if (otherValue.signum() == 0) throw context.runtime.newZeroDivisionError();
return bignorm(context.runtime, value.remainder(otherValue));
}

@JRubyMethod(name = "remainder", required = 1)
@Deprecated
public IRubyObject remainder19(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFloat && ((RubyFloat) other).getDoubleValue() == 0) {
throw context.runtime.newZeroDivisionError();
}
return remainder(context, other);
}

/** rb_big_quo
*
*/
@Override
@JRubyMethod(name = "quo", required = 1)
public IRubyObject quo(ThreadContext context, IRubyObject other) {
if (other instanceof RubyNumeric) {
if (((RubyNumeric) other).getDoubleValue() == 0) {
throw context.runtime.newZeroDivisionError();
}
return RubyFloat.newFloat(getRuntime(), big2dbl(this) / ((RubyNumeric) other).getDoubleValue());
} else {
return coerceBin(context, sites(context).quo, other);
}
}

@JRubyMethod(name = "quo", required = 1)
public IRubyObject quo19(ThreadContext context, IRubyObject other) {
if (other instanceof RubyInteger && ((RubyInteger) other).getDoubleValue() == 0) {
throw context.runtime.newZeroDivisionError();
}
@Deprecated
public final IRubyObject quo19(ThreadContext context, IRubyObject other) {
return quo(context, other);
}

/** rb_big_pow
*
*/
public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
return op_pow19(context, other);
}

public IRubyObject op_pow(final ThreadContext context, final long other) {
warnIfPowExponentTooBig(context, other);

if (other >= 0) {
if ( other <= Integer.MAX_VALUE ) { // only have BigInteger#pow(int)
return bignorm(context.runtime, value.pow((int) other)); // num2int is also implemented
}
}
return RubyFloat.newFloat(context.runtime, Math.pow(big2dbl(this), (double) other));
}

private void warnIfPowExponentTooBig(final ThreadContext context, final double other) {
// MRI issuses warning here on (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024)
if ( ((value.bitLength() + 7) / 8) * 4 * Math.abs(other) > 1024 * 1024 ) {
context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big");
}
}

/** rb_big_pow
*
*/
@JRubyMethod(name = {"**", "power"}, required = 1)
public IRubyObject op_pow19(ThreadContext context, IRubyObject other) {
public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
if (other == RubyFixnum.zero(runtime)) return RubyFixnum.one(runtime);
double d;
@@ -637,6 +607,29 @@ public IRubyObject op_pow19(ThreadContext context, IRubyObject other) {
return RubyNumeric.dbl2num(runtime, pow);
}

public IRubyObject op_pow(final ThreadContext context, final long other) {
warnIfPowExponentTooBig(context, other);

if (other >= 0) {
if ( other <= Integer.MAX_VALUE ) { // only have BigInteger#pow(int)
return bignorm(context.runtime, value.pow((int) other)); // num2int is also implemented
}
}
return RubyFloat.newFloat(context.runtime, Math.pow(big2dbl(this), (double) other));
}

private void warnIfPowExponentTooBig(final ThreadContext context, final double other) {
// MRI issuses warning here on (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024)
if ( ((value.bitLength() + 7) / 8) * 4 * Math.abs(other) > 1024 * 1024 ) {
context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big");
}
}

@Deprecated
public IRubyObject op_pow19(ThreadContext context, IRubyObject other) {
return op_pow(context, other);
}

/** rb_big_and
*
*/
@@ -650,6 +643,7 @@ public IRubyObject op_and(ThreadContext context, IRubyObject other) {
return coerceBit(context, sites(context).op_and, other);
}

@Deprecated
public IRubyObject op_and19(ThreadContext context, IRubyObject other) {
return op_and(context, other);
}
@@ -660,10 +654,10 @@ public IRubyObject op_and19(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "|", required = 1)
public IRubyObject op_or(ThreadContext context, IRubyObject other) {
if (other instanceof RubyBignum) {
return bignorm(getRuntime(), value.or(((RubyBignum) other).value));
return bignorm(context.runtime, value.or(((RubyBignum) other).value));
}
if (other instanceof RubyFixnum) { // no bignorm here needed
return bignorm(getRuntime(), value.or(fix2big((RubyFixnum)other)));
return bignorm(context.runtime, value.or(fix2big((RubyFixnum)other)));
}
return coerceBit(context, sites(context).op_or, other);
}
@@ -673,6 +667,7 @@ public IRubyObject bit_length(ThreadContext context) {
return context.runtime.newFixnum(value.bitLength());
}

@Deprecated
public IRubyObject op_or19(ThreadContext context, IRubyObject other) {
return op_or(context, other);
}
@@ -683,25 +678,19 @@ public IRubyObject op_or19(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "^", required = 1)
public IRubyObject op_xor(ThreadContext context, IRubyObject other) {
if (other instanceof RubyBignum) {
return bignorm(getRuntime(), value.xor(((RubyBignum) other).value));
return bignorm(context.runtime, value.xor(((RubyBignum) other).value));
}
if (other instanceof RubyFixnum) {
return bignorm(getRuntime(), value.xor(BigInteger.valueOf(((RubyFixnum) other).getLongValue())));
return bignorm(context.runtime, value.xor(BigInteger.valueOf(((RubyFixnum) other).getLongValue())));
}
return coerceBit(context, sites(context).op_xor, other);
}

@Deprecated
public IRubyObject op_xor19(ThreadContext context, IRubyObject other) {
return op_xor(context, other);
}

private IRubyObject convertToInteger(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFloat) {
throw context.runtime.newTypeError("can't convert Float into Integer");
}
return other.convertToInteger();
}

/** rb_big_neg
*
*/
@@ -852,6 +841,7 @@ public IRubyObject eql_p(IRubyObject other) {
return op_equal(other);
}

@Deprecated
public IRubyObject eql_p19(IRubyObject other) {
return eql_p(other);
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -1702,7 +1702,7 @@ public static IRubyObject[] zipCommonConvert(Ruby runtime, IRubyObject[] args, S

// 1.9 tries to convert, and failing that tries to "each" elements into a new array
for (int i = 0; i < args.length; i++) {
IRubyObject result = TypeConverter.convertToTypeWithCheck19(args[i], Array, method);
IRubyObject result = TypeConverter.convertToTypeWithCheck(args[i], Array, method);
if (result.isNil()) {
result = takeItems(context, args[i]);
}
Loading