Skip to content

Commit

Permalink
Showing 102 changed files with 3,427 additions and 1,298 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ branches:
- /^ha-feature/

script: tool/travis_runner.sh
install: travis_retry ./mvnw -Pbootstrap clean install -Dinvoker.skip -Dmaven.test.skip
install: travis_retry ./mvnw -Pbootstrap clean install -B -Dinvoker.skip -Dmaven.test.skip

notifications:
irc:
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.5.0
9.1.0.0-SNAPSHOT
2 changes: 1 addition & 1 deletion bin/jruby.bash
Original file line number Diff line number Diff line change
@@ -383,7 +383,7 @@ if [ "$VERIFY_JRUBY" != "" ]; then
"-Djruby.home=$JRUBY_HOME" \
"-Djruby.lib=$JRUBY_HOME/lib" -Djruby.script=jruby \
"-Djruby.shell=$JRUBY_SHELL" \
$java_class $JRUBY_OPTS "$@"
$java_class $mode "$@"

# Record the exit status immediately, or it will be overridden.
JRUBY_STATUS=$?
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ DO NOT MODIFIY - GENERATED CODE
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.0.5.0</version>
<version>9.1.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-core</artifactId>
<name>JRuby Core</name>
13 changes: 13 additions & 0 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -189,6 +189,11 @@ private static RubyRational newRationalBang(ThreadContext context, IRubyObject c
private static RubyRational newRationalBang(ThreadContext context, IRubyObject clazz, IRubyObject x) {
return newRationalBang(context, clazz, x, RubyFixnum.one(context.runtime));
}

@Override
public ClassIndex getNativeClassIndex() {
return ClassIndex.RATIONAL;
}

private IRubyObject num;
private IRubyObject den;
@@ -405,6 +410,14 @@ public IRubyObject denominator(ThreadContext context) {
return den;
}

public IRubyObject getNumerator() {
return num;
}

public IRubyObject getDenominator() {
return den;
}

/** f_imul
*
*/
101 changes: 64 additions & 37 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -82,8 +82,8 @@
@JRubyClass(name="Time", include="Comparable")
public class RubyTime extends RubyObject {
public static final String UTC = "UTC";
@Deprecated // no longer used
public static final BigDecimal ONE_MILLION_BD = BigDecimal.valueOf(1000000);
public static final BigDecimal ONE_BILLION_BD = BigDecimal.valueOf(1000000000);
public static final BigInteger ONE_MILLION_BI = BigInteger.valueOf(1000000);
public static final BigDecimal ONE_THOUSAND_BD = BigDecimal.valueOf(1000);
private DateTime dt;
@@ -259,29 +259,59 @@ public static DateTimeZone getTimeZoneFromUtcOffset(Ruby runtime, IRubyObject ut
// mri: time.c num_exact
private static IRubyObject numExact(Ruby runtime, IRubyObject v) {
IRubyObject tmp;
if (v instanceof RubyFixnum || v instanceof RubyBignum) return v;
if (v.isNil()) exactTypeError(runtime, v);
if (!(v instanceof RubyRational)) { // Default unknown
if (v.respondsTo("to_r")) {
tmp = v.callMethod(runtime.getCurrentContext(), "to_r");
// WTF is this condition for? It responds to to_r and makes something which thinks it is a String?
if (tmp != null && v.respondsTo("to_str")) exactTypeError(runtime, v);
} else {
tmp = TypeConverter.checkIntegerType(runtime, v, "to_int");
if (tmp.isNil()) exactTypeError(runtime, v);
}
v = tmp;
boolean typeError = false;

switch (v.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
return v;

case RATIONAL:
break;

case STRING:
case NIL:
typeError = true;
break;

default:
if ((tmp = v.getMetaClass().finvokeChecked(runtime.getCurrentContext(), v, "to_r")) != null) {
/* test to_int method availability to reject non-Numeric
* objects such as String, Time, etc which have to_r method. */
if (!v.respondsTo("to_int")) {
typeError = true;
break;
}
v = tmp;
break;
}
if (!(tmp = TypeConverter.checkIntegerType(runtime, v, "to_int")).isNil()) {
v = tmp;
break;
}
typeError = true;
break;
}

if (v instanceof RubyFixnum || v instanceof RubyBignum) {
return v;
} else if (v instanceof RubyRational) {
RubyRational r = (RubyRational) v;
if (r.denominator(runtime.getCurrentContext()) == RubyFixnum.newFixnum(runtime, 1)) {
return r.numerator(runtime.getCurrentContext());
}
} else {
exactTypeError(runtime, v);
switch (v.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
return v;

case RATIONAL:
if (((RubyRational) v).getDenominator() == RubyFixnum.one(runtime)) {
v = ((RubyRational) v).getNumerator();
}
break;

default:
typeError = true;
break;
}

if (typeError) {
if (v.isNil()) throw runtime.newTypeError("can't convert nil into an exact number");
throw runtime.newTypeError("can't convert " + v.getMetaClass() + " into an exact number");
}

return v;
@@ -1032,6 +1062,8 @@ public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObjec
long nanosecs;
long millisecs;

arg = numExact(runtime, arg);

// In the case of two arguments, MRI will discard the portion of
// the first argument after a decimal point (i.e., "floor").
// However in the case of a single argument, any portion after
@@ -1057,23 +1089,15 @@ public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObjec
RubyRational rational = (RubyRational) arg;

// These could have rounding errors if numerator or denominator are not integral and < long. Can they be?
long numerator = rational.numerator(context).convertToInteger().getLongValue();
long denominator = rational.denominator(context).convertToInteger().getLongValue();
long numerator = rational.getNumerator().convertToInteger().getLongValue();
long denominator = rational.getDenominator().convertToInteger().getLongValue();

final BigDecimal secs;
if ( numerator <= Integer.MAX_VALUE ) {
secs = new BigDecimal(numerator * 1000);
}
else {
secs = BigDecimal.valueOf(numerator).multiply(ONE_THOUSAND_BD);
}
final BigDecimal millis = secs.divide(BigDecimal.valueOf(denominator), 12, RoundingMode.DOWN);

final BigInteger roundMillis = millis.toBigInteger();
BigInteger remainingNanos = millis.movePointRight(6).toBigInteger().subtract( roundMillis.multiply(ONE_MILLION_BI) );
BigDecimal nanosBD = BigDecimal.valueOf(numerator).divide(BigDecimal.valueOf(denominator), 50, BigDecimal.ROUND_HALF_UP).multiply(ONE_BILLION_BD);
BigInteger millis = nanosBD.divide(ONE_MILLION_BD).toBigInteger();
BigInteger nanos = nanosBD.remainder(ONE_MILLION_BD).toBigInteger();

millisecs = roundMillis.longValue();
nanosecs = remainingNanos.longValue();
millisecs = millis.longValue();
nanosecs = nanos.longValue();
}
} else {
nanosecs = 0;
@@ -1109,6 +1133,9 @@ public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObjec
long millisecs;
long nanosecs = 0;

arg1 = numExact(runtime, arg1);
arg2 = numExact(runtime, arg2);

if (arg1 instanceof RubyFloat || arg1 instanceof RubyRational) {
double dbl = RubyNumeric.num2dbl(arg1);
millisecs = (long) (dbl * 1000);
30 changes: 5 additions & 25 deletions core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
Original file line number Diff line number Diff line change
@@ -1518,31 +1518,11 @@ public IRubyObject to_int() {
public IRubyObject to_r(ThreadContext context) {
checkFloatDomain();

RubyArray i = split(context);
long sign = (long)i.get(0);
String digits = (String)i.get(1).toString();
long base = (long)i.get(2);
long power = (long)i.get(3);
long denomi_power = power - digits.length();

IRubyObject bigDigits = RubyBignum.newBignum(getRuntime(), (String)digits).op_mul(context, sign);
RubyBignum numerator;
if(bigDigits instanceof RubyBignum) {
numerator = (RubyBignum)bigDigits;
}
else {
numerator = RubyBignum.newBignum(getRuntime(), bigDigits.toString());
}
IRubyObject num, den;
if(denomi_power < 0) {
num = numerator;
den = RubyFixnum.newFixnum(getRuntime(), base).op_mul(context, RubyFixnum.newFixnum(getRuntime(), -denomi_power));
}
else {
num = numerator.op_pow(context, RubyFixnum.newFixnum(getRuntime(), base).op_mul(context, RubyFixnum.newFixnum(getRuntime(), denomi_power)));
den = RubyFixnum.newFixnum(getRuntime(), 1);
}
return RubyRational.newInstance(context, context.runtime.getRational(), num, den);
int scale = value.scale();
BigInteger numerator = value.scaleByPowerOfTen(scale).toBigInteger();
BigInteger denominator = BigInteger.valueOf((long)Math.pow(10, scale));

return RubyRational.newInstance(context, context.runtime.getRational(), RubyBignum.newBignum(context.runtime, numerator), RubyBignum.newBignum(context.runtime, denominator));
}

public IRubyObject to_int19() {
28 changes: 21 additions & 7 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -463,13 +463,19 @@ public void BEQInstr(BEQInstr beqInstr) {
@Override
public void BFalseInstr(BFalseInstr bFalseInstr) {
Operand arg1 = bFalseInstr.getArg1();
visit(arg1);
// this is a gross hack because we don't have distinction in boolean instrs between boxed and unboxed
if (!(arg1 instanceof TemporaryBooleanVariable) && !(arg1 instanceof UnboxedBoolean)) {
if (arg1 instanceof TemporaryBooleanVariable || arg1 instanceof UnboxedBoolean) {
// no need to unbox
visit(arg1);
jvmMethod().bfalse(getJVMLabel(bFalseInstr.getJumpTarget()));
} else if (arg1 instanceof UnboxedFixnum || arg1 instanceof UnboxedFloat) {
// always true, don't branch
} else {
// unbox
visit(arg1);
jvmAdapter().invokeinterface(p(IRubyObject.class), "isTrue", sig(boolean.class));
jvmMethod().bfalse(getJVMLabel(bFalseInstr.getJumpTarget()));
}
jvmMethod().bfalse(getJVMLabel(bFalseInstr.getJumpTarget()));
}

@Override
@@ -721,12 +727,20 @@ public void BreakInstr(BreakInstr breakInstr) {
@Override
public void BTrueInstr(BTrueInstr btrueinstr) {
Operand arg1 = btrueinstr.getArg1();
visit(arg1);
// this is a gross hack because we don't have distinction in boolean instrs between boxed and unboxed
if (!(arg1 instanceof TemporaryBooleanVariable) && !(arg1 instanceof UnboxedBoolean)) {
jvmMethod().isTrue();
if (arg1 instanceof TemporaryBooleanVariable || arg1 instanceof UnboxedBoolean) {
// no need to unbox, just branch
visit(arg1);
jvmMethod().btrue(getJVMLabel(btrueinstr.getJumpTarget()));
} else if (arg1 instanceof UnboxedFixnum || arg1 instanceof UnboxedFloat) {
// always true, always branch
jvmMethod().goTo(getJVMLabel(btrueinstr.getJumpTarget()));
} else {
// unbox and branch
visit(arg1);
jvmAdapter().invokeinterface(p(IRubyObject.class), "isTrue", sig(boolean.class));
jvmMethod().btrue(getJVMLabel(btrueinstr.getJumpTarget()));
}
jvmMethod().btrue(getJVMLabel(btrueinstr.getJumpTarget()));
}

@Override
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -319,7 +319,7 @@ public static long strLengthWithCodeRange(Encoding enc, byte[]bytes, int p, int
}
}

private static long strLengthWithCodeRangeAsciiCompatible(Encoding enc, byte[]bytes, int p, int end) {
public static long strLengthWithCodeRangeAsciiCompatible(Encoding enc, byte[]bytes, int p, int end) {
int cr = 0, c = 0;
while (p < end) {
if (Encoding.isAscii(bytes[p])) {
@@ -341,7 +341,7 @@ private static long strLengthWithCodeRangeAsciiCompatible(Encoding enc, byte[]by
return pack(c, cr == 0 ? CR_7BIT : cr);
}

private static long strLengthWithCodeRangeNonAsciiCompatible(Encoding enc, byte[]bytes, int p, int end) {
public static long strLengthWithCodeRangeNonAsciiCompatible(Encoding enc, byte[]bytes, int p, int end) {
int cr = 0, c = 0;
for (c = 0; p < end; c++) {
int cl = preciseLength(enc, bytes, p, end);
@@ -365,7 +365,7 @@ public static long strLengthWithCodeRange(ByteList bytes, Encoding enc) {
}

// arg cannot be negative
static long pack(int result, int arg) {
public static long pack(int result, int arg) {
return ((long)arg << 31) | result;
}

8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
@@ -1842,12 +1842,12 @@ public static Encoding getEncoding(ByteList str) {

// MRI: get_actual_encoding
public static Encoding getActualEncoding(Encoding enc, ByteList byteList) {
return getActualEncoding(enc, byteList.getUnsafeBytes(), byteList.begin(), byteList.begin() + byteList.realSize());
}

public static Encoding getActualEncoding(Encoding enc, byte[] bytes, int p, int end) {
if (enc.isDummy() && enc instanceof UnicodeEncoding) {
// handle dummy UTF-16 and UTF-32 by scanning for BOM, as in MRI
byte[] bytes = byteList.unsafeBytes();
int p = byteList.begin();
int end = p + byteList.getRealSize();

if (enc == UTF16Dummy && end - p >= 2) {
int c0 = bytes[p] & 0xff;
int c1 = bytes[p + 1] & 0xff;
2 changes: 1 addition & 1 deletion lib/pom.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ def initialize( name, version, default_spec = true )

default_gems =
[
ImportedGem.new( 'jruby-openssl', '0.9.11' ),
ImportedGem.new( 'jruby-openssl', '0.9.15' ),
ImportedGem.new( 'jruby-readline', '1.0', false ),
ImportedGem.new( 'rake', '${rake.version}' ),
ImportedGem.new( 'rdoc', '${rdoc.version}' ),
6 changes: 3 additions & 3 deletions lib/pom.xml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ DO NOT MODIFIY - GENERATED CODE
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.0.5.0</version>
<version>9.1.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-stdlib</artifactId>
<name>JRuby Lib Setup</name>
@@ -28,13 +28,13 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-core</artifactId>
<version>9.0.5.0</version>
<version>9.1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>jruby-openssl</artifactId>
<version>0.9.11</version>
<version>0.9.15</version>
<type>gem</type>
<scope>provided</scope>
<exclusions>
Loading

0 comments on commit f401884

Please sign in to comment.