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: 2a5b495ce4c9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1e41a7ddf8b0
Choose a head ref
  • 5 commits
  • 8 files changed
  • 1 contributor

Commits on Aug 8, 2017

  1. Copy the full SHA
    68ea9a3 View commit details
  2. Copy the full SHA
    056ec1e View commit details
  3. Copy the full SHA
    49b84b9 View commit details
  4. Copy the full SHA
    a126c51 View commit details
  5. Copy the full SHA
    1e41a7d View commit details
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -397,15 +397,15 @@ public RubyString to_s(IRubyObject arg0) {
*/
@Override
public IRubyObject coerce(IRubyObject other) {
Ruby runtime = getRuntime();
final Ruby runtime = getRuntime();
if (other instanceof RubyFixnum) {
return getRuntime().newArray(newBignum(getRuntime(), ((RubyFixnum) other).getLongValue()), this);
return runtime.newArray(newBignum(runtime, ((RubyFixnum) other).getLongValue()), this);
}
if (other instanceof RubyBignum) {
return getRuntime().newArray(newBignum(getRuntime(), ((RubyBignum) other).getValue()), this);
return runtime.newArray(newBignum(runtime, ((RubyBignum) other).getValue()), this);
}

return RubyArray.newArray(runtime, RubyKernel.new_float(this, other), RubyKernel.new_float(this, this));
return RubyArray.newArray(runtime, RubyKernel.new_float(runtime, other), RubyKernel.new_float(runtime, this));
}

/** rb_big_uminus
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -255,7 +255,8 @@ public IRubyObject to_s() {
@JRubyMethod(name = "coerce", required = 1)
@Override
public IRubyObject coerce(IRubyObject other) {
return getRuntime().newArray(RubyKernel.new_float(this, other), this);
final Ruby runtime = getRuntime();
return runtime.newArray(RubyKernel.new_float(runtime, other), this);
}

/** flo_uminus
38 changes: 8 additions & 30 deletions core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@
package org.jruby;

import org.jcodings.Encoding;
import org.jcodings.exception.EncodingException;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.anno.JRubyClass;
@@ -49,7 +48,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;
import org.jruby.util.io.EncodingUtils;

import java.math.RoundingMode;
@@ -144,9 +142,8 @@ public IRubyObject upto(ThreadContext context, IRubyObject to, Block block) {

private static void fixnumUpto(ThreadContext context, long from, long to, Block block) {
// We must avoid "i++" integer overflow when (to == Long.MAX_VALUE).
Ruby runtime = context.runtime;
if (block.getSignature() == Signature.NO_ARGUMENTS) {
IRubyObject nil = runtime.getNil();
IRubyObject nil = context.nil;
long i;
for (i = from; i < to; i++) {
block.yield(context, nil);
@@ -155,6 +152,7 @@ private static void fixnumUpto(ThreadContext context, long from, long to, Block
block.yield(context, nil);
}
} else {
Ruby runtime = context.runtime;
long i;
for (i = from; i < to; i++) {
block.yield(context, RubyFixnum.newFixnum(runtime, i));
@@ -207,9 +205,8 @@ public IRubyObject downto(ThreadContext context, IRubyObject to, Block block) {

private static void fixnumDownto(ThreadContext context, long from, long to, Block block) {
// We must avoid "i--" integer overflow when (to == Long.MIN_VALUE).
Ruby runtime = context.runtime;
if (block.getSignature() == Signature.NO_ARGUMENTS) {
IRubyObject nil = runtime.getNil();
IRubyObject nil = context.nil;
long i;
for (i = from; i > to; i--) {
block.yield(context, nil);
@@ -218,6 +215,7 @@ private static void fixnumDownto(ThreadContext context, long from, long to, Bloc
block.yield(context, nil);
}
} else {
Ruby runtime = context.runtime;
long i;
for (i = from; i > to; i--) {
block.yield(context, RubyFixnum.newFixnum(runtime, i));
@@ -229,9 +227,8 @@ private static void fixnumDownto(ThreadContext context, long from, long to, Bloc
}

private static void duckDownto(ThreadContext context, IRubyObject from, IRubyObject to, Block block) {
Ruby runtime = context.runtime;
IRubyObject i = from;
RubyFixnum one = RubyFixnum.one(runtime);
RubyFixnum one = RubyFixnum.one(context.runtime);
while (true) {
if (sites(context).op_lt.call(context, i, i, to).isTrue()) {
break;
@@ -374,24 +371,6 @@ public final RubyString chr19(ThreadContext context, IRubyObject arg) {
return chr(context, arg);
}

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

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

ByteList bytes = new ByteList(n);

enc.codeToMbc((int)value, bytes.getUnsafeBytes(), 0);
boolean ok = StringSupport.preciseLength(enc, bytes.unsafeBytes(), 0, n) == n;

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

bytes.setRealSize(n);
return bytes;
}

/** int_ord
*
*/
@@ -444,18 +423,17 @@ public IRubyObject round(ThreadContext context, IRubyObject _digits) {
}

@JRubyMethod(name = "round")
public IRubyObject round(ThreadContext context, IRubyObject _digits, IRubyObject _opts) {
public IRubyObject round(ThreadContext context, IRubyObject digits, IRubyObject _opts) {
Ruby runtime = context.runtime;
int ndigits = 0;

// options (only "half" right now)
IRubyObject opts = ArgsUtil.getOptionsArg(runtime, _opts);
ndigits = num2int(_digits);
int ndigits = num2int(digits);

RoundingMode roundingMode = getRoundingMode(context, opts);

if (ndigits > 0) {
return RubyKernel.new_float19(runtime.getFloat(), this);
return RubyKernel.new_float(runtime, this);
}
if (ndigits == 0) {
return this;
57 changes: 36 additions & 21 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -383,35 +383,50 @@ public static IRubyObject new_rational(ThreadContext context, IRubyObject recv,
return sites(context).convert_rational.call(context, rational, rational, arg0, arg1);
}

public static RubyFloat new_float(IRubyObject recv, IRubyObject object) {
return new_float19(recv, object);
@Deprecated
public static RubyFloat new_float19(IRubyObject recv, IRubyObject object) {
return new_float(recv, object);
}

@JRubyMethod(name = "Float", module = true, visibility = PRIVATE)
public static RubyFloat new_float19(IRubyObject recv, IRubyObject object) {
Ruby runtime = recv.getRuntime();
if(object instanceof RubyFixnum){
return RubyFloat.newFloat(runtime, ((RubyFixnum)object).getDoubleValue());
} else if (object instanceof RubyFloat) {
return (RubyFloat)object;
} else if(object instanceof RubyBignum){
return RubyFloat.newFloat(runtime, RubyBignum.big2dbl((RubyBignum)object));
} else if(object instanceof RubyString){
if(((RubyString) object).getByteList().getRealSize() == 0){ // rb_cstr_to_dbl case
public static RubyFloat new_float(IRubyObject recv, IRubyObject object) {
return new_float(recv.getRuntime(), object);
}

private static final ByteList ZEROx = new ByteList(new byte[] { '0','x' }, false);

static RubyFloat new_float(final Ruby runtime, IRubyObject object) {
if (object instanceof RubyInteger){
return new_float(runtime, (RubyInteger) object);
}
if (object instanceof RubyFloat) {
return (RubyFloat) object;
}
if (object instanceof RubyString){
RubyString str = (RubyString) object;
ByteList bytes = str.getByteList();
if (bytes.getRealSize() == 0){ // rb_cstr_to_dbl case
throw runtime.newArgumentError("invalid value for Float(): " + object.inspect());
}
RubyString arg = (RubyString)object;
if (arg.toString().startsWith("0x")) {
return ConvertBytes.byteListToInum(runtime, arg.getByteList(), 16, true).toFloat();

if (bytes.startsWith(ZEROx)) { // startsWith("0x")
return ConvertBytes.byteListToInum(runtime, bytes, 16, true).toFloat();
}
return RubyNumeric.str2fnum(runtime, arg, true);
} else if(object.isNil()){
return RubyNumeric.str2fnum(runtime, str, true);
}
if (object.isNil()){
throw runtime.newTypeError("can't convert nil into Float");
} else {
ThreadContext context = runtime.getCurrentContext();
KernelSites sites = sites(context);
return (RubyFloat)TypeConverter.convertToType(context, object, runtime.getFloat(), sites.to_f_checked);
}
ThreadContext context = runtime.getCurrentContext();
KernelSites sites = sites(context);
return (RubyFloat) TypeConverter.convertToType(context, object, runtime.getFloat(), sites.to_f_checked);
}

static RubyFloat new_float(final Ruby runtime, RubyInteger num) {
if (num instanceof RubyBignum) {
return RubyFloat.newFloat(runtime, RubyBignum.big2dbl((RubyBignum) num));
}
return RubyFloat.newFloat(runtime, ((RubyFixnum) num).getDoubleValue());
}

@JRubyMethod(name = "Hash", required = 1, module = true, visibility = PRIVATE)
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyMath.java
Original file line number Diff line number Diff line change
@@ -298,7 +298,7 @@ public static RubyFloat atanh_19(ThreadContext context, IRubyObject recv, IRubyO
}

private static double atanh_common(IRubyObject recv, IRubyObject x) {
double value = ((RubyFloat)RubyKernel.new_float(recv,x)).getDoubleValue();
double value = RubyKernel.new_float(recv.getRuntime(), x).getDoubleValue();
double y = Math.abs(value);
double result;

@@ -680,7 +680,7 @@ public static RubyFloat erfc19(ThreadContext context, IRubyObject recv, IRubyObj

@JRubyMethod(name = "gamma", required = 1, module = true, visibility = Visibility.PRIVATE)
public static RubyFloat gamma(ThreadContext context, IRubyObject recv, IRubyObject x) {
double value = RubyKernel.new_float(recv, x).getDoubleValue();
double value = RubyKernel.new_float(context.runtime, x).getDoubleValue();
double result = nemes_gamma(value);
/* note nemes_gamma can return Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY
* when value is an integer less than 1.
@@ -719,7 +719,7 @@ public static RubyFloat gamma(ThreadContext context, IRubyObject recv, IRubyObje

@JRubyMethod(name = "lgamma", required = 1, module = true, visibility = Visibility.PRIVATE)
public static RubyArray lgamma(ThreadContext context, IRubyObject recv, IRubyObject x) {
double value = RubyKernel.new_float(recv, x).getDoubleValue();
double value = RubyKernel.new_float(context.runtime, x).getDoubleValue();
// JRUBY-4653: Could this error checking done more elegantly?
if (value < 0 && Double.isInfinite(value)) throw context.runtime.newMathDomainError("lgamma");

9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -666,12 +666,13 @@ public IRubyObject initialize_copy(IRubyObject arg) {
*/
@JRubyMethod(name = "coerce")
public IRubyObject coerce(IRubyObject other) {
if (getMetaClass() == other.getMetaClass()) return getRuntime().newArray(other, this);
final Ruby runtime = getRuntime();
if (getMetaClass() == other.getMetaClass()) return runtime.newArray(other, this);

IRubyObject cdr = RubyKernel.new_float(this, this);
IRubyObject car = RubyKernel.new_float(this, other);
IRubyObject cdr = RubyKernel.new_float(runtime, this);
IRubyObject car = RubyKernel.new_float(runtime, other);

return getRuntime().newArray(car, cdr);
return runtime.newArray(car, cdr);
}

/** num_uplus
13 changes: 2 additions & 11 deletions core/src/main/java/org/jruby/util/Sprintf.java
Original file line number Diff line number Diff line change
@@ -887,19 +887,10 @@ else if ((flags & FLAG_MINUS) != 0) {
case 'g': {
arg = args.getArg();

if (!(arg instanceof RubyFloat)) {
// FIXME: what is correct 'recv' argument?
// (this does produce the desired behavior)
if (usePrefixForZero) {
arg = RubyKernel.new_float(arg,arg);
} else {
arg = RubyKernel.new_float19(arg,arg);
}
}
double dval = ((RubyFloat)arg).getDoubleValue();
double dval = RubyKernel.new_float(runtime.getFloat(), arg).getDoubleValue();
boolean nan = dval != dval;
boolean inf = dval == Double.POSITIVE_INFINITY || dval == Double.NEGATIVE_INFINITY;
boolean negative = dval < 0.0d || (dval == 0.0d && (new Float(dval)).equals(new Float(-0.0)));
boolean negative = dval < 0.0d || (dval == 0.0d && Double.doubleToLongBits(dval) == Double.doubleToLongBits(-0.0));

byte[] digits;
int nDigits = 0;
13 changes: 6 additions & 7 deletions core/src/main/java/org/jruby/util/TypeConverter.java
Original file line number Diff line number Diff line change
@@ -115,18 +115,22 @@ public static IRubyObject convertToType(ThreadContext context, IRubyObject obj,
return val;
}

@Deprecated // not-used
public static IRubyObject convertToType19(IRubyObject obj, RubyClass target, String convertMethod, boolean raise) {
return convertToType(obj, target, convertMethod, raise);
}

@Deprecated // not-used
public static IRubyObject convertToType19(ThreadContext context, IRubyObject obj, RubyClass target, JavaSites.CheckedSites sites, boolean raise) {
return convertToType(context, obj, target, sites, raise);
}

@Deprecated // not-used
public static IRubyObject convertToType19(IRubyObject obj, RubyClass target, String convertMethod) {
return convertToType(obj, target, convertMethod);
}

@Deprecated // not-used
public static IRubyObject convertToType19(ThreadContext context, IRubyObject obj, RubyClass target, JavaSites.CheckedSites sites) {
return convertToType(context, obj, target, sites);
}
@@ -399,20 +403,15 @@ public static IRubyObject convertToInteger(ThreadContext context, IRubyObject va

if (base != 0) {
tmp = TypeConverter.checkStringType(context.runtime, val);
if (!tmp.isNil()) {
continue;
}
if (tmp != context.nil) continue;
raiseIntegerBaseError(context);
}

break;
}

tmp = TypeConverter.convertToType(context, val, runtime.getString(), "to_int", false);
if (tmp.isNil()) {
return val.convertToInteger("to_i");
}
return tmp;
return (tmp != context.nil) ? tmp : val.convertToInteger("to_i");
}

// MRI: rb_Array