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

Commits on Apr 1, 2016

  1. Copy the full SHA
    afd765a View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6e3c07d View commit details
  3. [ji] support (value equality) == of Ruby arrays to Java arrays

    ... this is consistent since we already seamlessly convert Ruby arrays to Java ones
    kares committed Apr 1, 2016
    Copy the full SHA
    cf8c486 View commit details
  4. Copy the full SHA
    6c68d71 View commit details
  5. Copy the full SHA
    955395f View commit details
  6. Copy the full SHA
    808784c View commit details
  7. [ji] handle 2.3 #dig on Java arrays - could be useful for digging out…

    … nested Java arrays
    
    ... potentially mixed up with / wrapped in Ruby arrays
    kares committed Apr 1, 2016
    Copy the full SHA
    1150a01 View commit details
  8. initialize cause for Java class loading errors so that its easier to …

    …identify the issue
    
    ... esp. in embed mode where RaiseException will show the cause on err
    kares committed Apr 1, 2016
    Copy the full SHA
    d8920ad View commit details
  9. cleanup NativeException - improve joined Java+Ruby backtrace generation

    ... (without a lot of copying due previous RubyArray unshift-ing)
    kares committed Apr 1, 2016
    Copy the full SHA
    d2a1ed3 View commit details
  10. Copy the full SHA
    feb3c57 View commit details
49 changes: 30 additions & 19 deletions core/src/main/java/org/jruby/NativeException.java
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public NativeException(Ruby runtime, RubyClass rubyClass, Throwable cause) {
private NativeException(Ruby runtime, RubyClass rubyClass) {
super(runtime, rubyClass);
this.cause = new Throwable();
this.message = runtime.newString();
this.message = RubyString.newEmptyString(runtime);
}

private static ObjectAllocator NATIVE_EXCEPTION_ALLOCATOR = new ObjectAllocator() {
@@ -72,32 +72,43 @@ public static RubyClass createClass(Ruby runtime, RubyClass baseClass) {
}

@JRubyMethod
public final IRubyObject cause() {
return Java.getInstance(getRuntime(), getCause());
}

@Deprecated
public IRubyObject cause(Block unusedBlock) {
return Java.getInstance(getRuntime(), cause);
return cause();
}

public IRubyObject backtrace() {
@Override
public final IRubyObject backtrace() {
IRubyObject rubyTrace = super.backtrace();
if (rubyTrace.isNil()) {
return rubyTrace;
}
if ( rubyTrace.isNil() ) return rubyTrace;

final Ruby runtime = getRuntime();
RubyArray array = (RubyArray) rubyTrace.dup();
StackTraceElement[] stackTrace = cause.getStackTrace();
for (int i = stackTrace.length - 1; i >= 0; i--) {
StackTraceElement element = stackTrace[i];
final RubyArray rTrace = (RubyArray) rubyTrace;
StackTraceElement[] jTrace = cause.getStackTrace();
final IRubyObject[] trace = new IRubyObject[jTrace.length + rTrace.size()];
final StringBuilder line = new StringBuilder(32);
for ( int i = 0; i < jTrace.length; i++ ) {
StackTraceElement element = jTrace[i];
final String className = element.getClassName();
final String line;
line.setLength(0);
if (element.getFileName() == null) {
line = className + ':' + element.getLineNumber() + ":in `" + element.getMethodName() + '\'';
line.append(className).append(':').append(element.getLineNumber()).append(":in `").append(element.getMethodName()).append('\'');
} else {
final int index = className.lastIndexOf('.');
final String packageName = index == -1 ? "" : className.substring(0, index) + '/';
line = packageName.replace('.', '/') + element.getFileName() + ':' + element.getLineNumber() + ":in `" + element.getMethodName() + '\'';
if ( index > - 1 ) {
line.append(className.substring(0, index).replace('.', '/'));
line.append('/');
}
line.append(element.getFileName()).append(':').append(element.getLineNumber()).append(":in `").append(element.getMethodName()).append('\'');
}
array.unshift(runtime.newString(line));
trace[i] = RubyString.newString(runtime, line.toString());
}
return array;
System.arraycopy(rTrace.toJavaArrayMaybeUnsafe(), 0, trace, jTrace.length, rTrace.size());
return RubyArray.newArrayNoCopy(runtime, trace);
}

@Deprecated // not used
@@ -155,9 +166,9 @@ private static String searchStackMessage(Throwable cause) {
String message;
do {
message = cause.getMessage();
if ( message != null ) return message;
cause = cause.getCause();
} while (message == null && cause != null);

return message;
} while ( cause != null );
return null;
}
}
30 changes: 16 additions & 14 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -1189,32 +1189,28 @@ public int compareTo(IRubyObject other) {
return 0;
}

@Override
public IRubyObject op_equal(ThreadContext context, IRubyObject obj) {
return op_equal_19(context, obj);
}

/** rb_obj_equal
*
* Will by default use identity equality to compare objects. This
* follows the Ruby semantics.
*
* The name of this method doesn't follow the convention because hierarchy problems
*/
@Override
@JRubyMethod(name = "==")
public IRubyObject op_equal_19(ThreadContext context, IRubyObject obj) {
public IRubyObject op_equal(ThreadContext context, IRubyObject obj) {
return this == obj ? context.runtime.getTrue() : context.runtime.getFalse();
}

@Deprecated
public IRubyObject op_equal_19(ThreadContext context, IRubyObject obj) {
return op_equal(context, obj);
}

@Override
public IRubyObject op_eqq(ThreadContext context, IRubyObject other) {
// Remain unimplemented due to problems with the double java hierarchy
return context.runtime.getNil();
}

@JRubyMethod(name = "equal?", required = 1)
public IRubyObject equal_p19(ThreadContext context, IRubyObject other) {
return op_equal_19(context, other);
return context.nil;
}

/**
@@ -1931,8 +1927,14 @@ private void callFinalizer(IRubyObject finalizer) {
*
* Will use Java identity equality.
*/
public IRubyObject equal_p(ThreadContext context, IRubyObject obj) {
return this == obj ? context.runtime.getTrue() : context.runtime.getFalse();
@JRubyMethod(name = "equal?", required = 1)
public IRubyObject equal_p(ThreadContext context, IRubyObject other) {
return this == other ? context.runtime.getTrue() : context.runtime.getFalse();
}

@Deprecated
public IRubyObject equal_p19(ThreadContext context, IRubyObject other) {
return equal_p(context, other);
}

/** rb_obj_equal
20 changes: 9 additions & 11 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -638,6 +638,7 @@ public IRubyObject op_pow19(ThreadContext context, IRubyObject other) {
/** rb_big_and
*
*/
@JRubyMethod(name = "&", required = 1)
public IRubyObject op_and(ThreadContext context, IRubyObject other) {
if (other instanceof RubyBignum) {
return bignorm(getRuntime(), value.and(((RubyBignum) other).value));
@@ -647,14 +648,14 @@ public IRubyObject op_and(ThreadContext context, IRubyObject other) {
return coerceBit(context, "&", other);
}

@JRubyMethod(name = "&", required = 1)
public IRubyObject op_and19(ThreadContext context, IRubyObject other) {
return op_and(context, other);
}

/** rb_big_or
*
*/
@JRubyMethod(name = "|", required = 1)
public IRubyObject op_or(ThreadContext context, IRubyObject other) {
if (other instanceof RubyBignum) {
return bignorm(getRuntime(), value.or(((RubyBignum) other).value));
@@ -665,14 +666,14 @@ public IRubyObject op_or(ThreadContext context, IRubyObject other) {
return coerceBit(context, "|", other);
}

@JRubyMethod(name = "|", required = 1)
public IRubyObject op_or19(ThreadContext context, IRubyObject other) {
return op_or(context, other);
}

/** rb_big_xor
*
*/
@JRubyMethod(name = "^", required = 1)
public IRubyObject op_xor(ThreadContext context, IRubyObject other) {
if (other instanceof RubyBignum) {
return bignorm(getRuntime(), value.xor(((RubyBignum) other).value));
@@ -682,8 +683,7 @@ public IRubyObject op_xor(ThreadContext context, IRubyObject other) {
}
return coerceBit(context, "^", other);
}

@JRubyMethod(name = "^", required = 1)

public IRubyObject op_xor19(ThreadContext context, IRubyObject other) {
return op_xor(context, other);
}
@@ -850,23 +850,21 @@ public IRubyObject op_equal(IRubyObject other) {
*
*/
@Override
@JRubyMethod(name = {"==="}, required = 1)
public IRubyObject eql_p(IRubyObject other) {
return eql_p19(other);
// '==' and '===' are the same, but they differ from 'eql?'.
return op_equal(other);
}

/**
* In ruby 1.9, '==' and '===' are the same, but they differ from 'eql?'.
*/
@JRubyMethod(name = {"==="}, required = 1)
public IRubyObject eql_p19(IRubyObject other) {
return op_equal(other);
return eql_p(other);
}

/** rb_big_hash
*
*/
@JRubyMethod(name = "hash")
@Override
@JRubyMethod(name = "hash")
public RubyFixnum hash() {
return getRuntime().newFixnum(value.hashCode());
}
45 changes: 14 additions & 31 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -159,11 +159,6 @@ public final boolean eql(IRubyObject other) {

@Override
public IRubyObject equal_p(ThreadContext context, IRubyObject obj) {
return equal_p19(context, obj);
}

@Override
public IRubyObject equal_p19(ThreadContext context, IRubyObject obj) {
return context.runtime.newBoolean(this == obj || eql(obj));
}

@@ -428,7 +423,7 @@ private IRubyObject addOther(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "-")
public IRubyObject op_minus(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return subtractFixnum(context, (RubyFixnum)other);
return subtractFixnum(context, (RubyFixnum) other);
}
return subtractOther(context, other);
}
@@ -490,7 +485,7 @@ private IRubyObject subtractOther(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "*")
public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return op_mul(context, ((RubyFixnum)other).value);
return op_mul(context, ((RubyFixnum) other).value);
} else {
return multiplyOther(context, other);
}
@@ -630,7 +625,7 @@ private IRubyObject idivLong(ThreadContext context, long x, long y) {
public IRubyObject op_mod(ThreadContext context, IRubyObject other) {
checkZeroDivisionError(context, other);
if (other instanceof RubyFixnum) {
return moduloFixnum(context, (RubyFixnum)other);
return moduloFixnum(context, (RubyFixnum) other);
}
return coerceBin(context, "%", other);
}
@@ -893,7 +888,7 @@ private int compareToOther(IRubyObject other) {
@JRubyMethod(name = "<=>")
public IRubyObject op_cmp(ThreadContext context, IRubyObject other) {
return other instanceof RubyFixnum ?
op_cmp(context, ((RubyFixnum)other).value) : compareOther(context, other);
op_cmp(context, ((RubyFixnum) other).value) : compareOther(context, other);
}

public IRubyObject op_cmp(ThreadContext context, long other) {
@@ -907,7 +902,7 @@ private IRubyObject compareOther(ThreadContext context, IRubyObject other) {
return newFixnum(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum)other).getValue()));
}
if (other instanceof RubyFloat) {
return dbl_cmp(context.runtime, (double)value, ((RubyFloat)other).getDoubleValue());
return dbl_cmp(context.runtime, (double) value, ((RubyFloat) other).getDoubleValue());
}
return coerceCmp(context, "<=>", other);
}
@@ -979,7 +974,7 @@ private IRubyObject op_geOther(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "<")
public IRubyObject op_lt(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return op_lt(context, ((RubyFixnum)other).value);
return op_lt(context, ((RubyFixnum) other).value);
}
return op_ltOther(context, other);
}
@@ -1046,7 +1041,11 @@ public IRubyObject op_neg() {
*/
@JRubyMethod(name = "&")
public IRubyObject op_and(ThreadContext context, IRubyObject other) {
return op_and19(context, other);
if (!((other = bitCoerce(context, other)) instanceof RubyFixnum)) {
return ((RubyBignum) other).op_and(context, this);
}

return op_andOther(context, other);
}

private IRubyObject op_andOther(ThreadContext context, IRubyObject other) {
@@ -1060,14 +1059,6 @@ public IRubyObject op_and(ThreadContext context, long other) {
return newFixnum(context.runtime, value & other);
}

private IRubyObject op_and19(ThreadContext context, IRubyObject other) {
if (!((other = bitCoerce(context, other)) instanceof RubyFixnum)) {
return ((RubyBignum) other).op_and(context, this);
}

return op_andOther(context, other);
}

/** fix_or
*
*/
@@ -1089,10 +1080,9 @@ public IRubyObject op_or(ThreadContext context, long other) {
*/
@JRubyMethod(name = "^")
public IRubyObject op_xor(ThreadContext context, IRubyObject other) {
return op_xor19(context, other);
}

private IRubyObject op_xor18(ThreadContext context, IRubyObject other) {
if (!((other = bitCoerce(context, other)) instanceof RubyFixnum)) {
return ((RubyBignum) other).op_xor(context, this);
}
if (other instanceof RubyFixnum || (other = fixCoerce(other)) instanceof RubyFixnum) {
return newFixnum(context.runtime, value ^ ((RubyFixnum) other).value);
}
@@ -1103,13 +1093,6 @@ public IRubyObject op_xor(ThreadContext context, long other) {
return newFixnum(context.runtime, value ^ other);
}

private IRubyObject op_xor19(ThreadContext context, IRubyObject other) {
if (!((other = bitCoerce(context, other)) instanceof RubyFixnum)) {
return ((RubyBignum) other).op_xor(context, this);
}
return op_xor18(context, other);
}

/** fix_aref
*
*/
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyObject.java
Original file line number Diff line number Diff line change
@@ -517,7 +517,7 @@ public static RubyString inspect(ThreadContext context, IRubyObject object) {
}

// MRI: rb_obj_dig
static IRubyObject dig(ThreadContext context, IRubyObject obj, IRubyObject[] args, int idx) {
public static IRubyObject dig(ThreadContext context, IRubyObject obj, IRubyObject[] args, int idx) {
if ( obj.isNil() ) return context.nil;
if ( obj instanceof RubyArray ) {
// TODO: cache somewhere
Loading