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

Commits on Nov 7, 2014

  1. Copy the full SHA
    10f7229 View commit details
  2. Implement a half-assed Etc.uname.

    This needs to have a full native version so we present accurate
    values. I've filed #2145 for a better version.
    headius committed Nov 7, 2014
    Copy the full SHA
    9576d09 View commit details
Showing with 39 additions and 0 deletions.
  1. +9 −0 core/src/main/java/org/jruby/RubyComparable.java
  2. +29 −0 core/src/main/java/org/jruby/ext/etc/RubyEtc.java
  3. +1 −0 test/mri/excludes/TestAssignment.rb
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/RubyComparable.java
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@

import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.common.RubyWarnings;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
@@ -144,6 +145,7 @@ private static IRubyObject callCmpMethod(ThreadContext context, IRubyObject recv

return RubyBoolean.newBoolean(runtime, cmpint(context, result, recv, other) == 0);
} catch (RaiseException e) {
cmpFailed(context);
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
// clear error info resulting from failure to compare (JRUBY-3292)
runtime.getGlobalVariables().set("$!", savedError);
@@ -155,6 +157,13 @@ private static IRubyObject callCmpMethod(ThreadContext context, IRubyObject recv
}
}

private static void cmpFailed(ThreadContext context) {
RubyWarnings warnings = context.runtime.getWarnings();

warnings.warn("Comparable#== will no more rescue exceptions of #<=> in the next release.");
warnings.warn("Return nil in #<=> if the comparison is inappropriate or avoid such comparison.");
}

/** cmp_gt
*
*/
29 changes: 29 additions & 0 deletions core/src/main/java/org/jruby/ext/etc/RubyEtc.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.jruby.ext.etc;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jruby.RubyHash;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.common.IRubyWarnings.ID;
@@ -20,6 +24,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.util.SafePropertyAccessor;

@JRubyModule(name="Etc")
public class RubyEtc {
@@ -435,6 +440,30 @@ public static IRubyObject nprocessors(ThreadContext context, IRubyObject recv) {
int nprocs = Runtime.getRuntime().availableProcessors();
return RubyFixnum.newFixnum(context.getRuntime(), nprocs);
}

@JRubyMethod(module = true)
public static IRubyObject uname(ThreadContext context, IRubyObject self) {
Ruby runtime = context.runtime;
RubyHash uname = RubyHash.newHash(runtime);

uname.op_aset(context,
runtime.newSymbol("sysname"),
runtime.newString(SafePropertyAccessor.getProperty("os.name", "unknown")));
try {
uname.op_aset(context,
runtime.newSymbol("nodename"),
runtime.newString(InetAddress.getLocalHost().getHostName()));
} catch (UnknownHostException uhe) {
uname.op_aset(context,
runtime.newSymbol("nodename"),
runtime.newString("unknown"));
}
uname.put(runtime.newSymbol("release"), runtime.newString("unknown"));
uname.put(runtime.newSymbol("version"), runtime.newString(SafePropertyAccessor.getProperty("os.version")));
uname.put(runtime.newSymbol("machine"), runtime.newString(SafePropertyAccessor.getProperty("os.arch")));

return uname;
}

private static final AtomicBoolean iteratingPasswd = new AtomicBoolean(false);
}
1 change: 1 addition & 0 deletions test/mri/excludes/TestAssignment.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
exclude :test_assign_private_self, "disagreement about visibility of attrs (MRI #9907)"
exclude :test_yield, "needs investigation"