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

Commits on Jul 5, 2017

  1. Copy the full SHA
    4f912f4 View commit details
  2. Copy the full SHA
    6e262f0 View commit details
  3. Copy the full SHA
    db1da1f View commit details
35 changes: 21 additions & 14 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -1503,12 +1503,18 @@ public static IRubyObject srand(ThreadContext context, IRubyObject recv, IRubyOb
return RubyRandom.srandCommon(context, recv, arg);
}

@Deprecated
public static IRubyObject rand18(ThreadContext context, IRubyObject recv, IRubyObject[] arg) {
return rand19(context, recv, arg);
return rand(context, recv, arg);
}

@JRubyMethod(name = "rand", module = true, optional = 1, visibility = PRIVATE)
@Deprecated
public static IRubyObject rand19(ThreadContext context, IRubyObject recv, IRubyObject[] arg) {
return rand(context, recv, arg);
}

@JRubyMethod(name = "rand", module = true, optional = 1, visibility = PRIVATE)
public static IRubyObject rand(ThreadContext context, IRubyObject recv, IRubyObject[] arg) {
return RubyRandom.randCommon19(context, recv, arg);
}

@@ -1522,12 +1528,8 @@ public static IRubyObject syscall(ThreadContext context, IRubyObject recv, IRuby
throw context.runtime.newNotImplementedError("Kernel#syscall is not implemented in JRuby");
}

public static IRubyObject system(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return system19(context, recv, args);
}

@JRubyMethod(name = "system", required = 1, rest = true, module = true, visibility = PRIVATE)
public static IRubyObject system19(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
public static IRubyObject system(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
final Ruby runtime = context.runtime;
boolean needChdir = !runtime.getCurrentDirectory().equals(runtime.getPosix().getcwd());

@@ -1559,9 +1561,8 @@ public static IRubyObject system19(ThreadContext context, IRubyObject recv, IRub
// #ifdef SIGCHLD
// signal(SIGCHLD, chfunc);
// #endif
if (pid < 0) {
return runtime.getNil();
}
if (pid < 0) return context.nil;

status = (int)((RubyProcess.RubyStatus) context.getLastExitStatus()).getStatus();
if (status == 0) return runtime.getTrue();
return runtime.getFalse();
@@ -1584,6 +1585,11 @@ public static IRubyObject system19(ThreadContext context, IRubyObject recv, IRub
}
}

@Deprecated
public static IRubyObject system19(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return system(context, recv, args);
}

private static int systemCommon(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
long[] tuple;
@@ -1732,14 +1738,15 @@ private static IRubyObject execCommon(Ruby runtime, IRubyObject env, IRubyObject
return runtime.getNil();
}

@JRubyMethod(name = "fork", module = true, visibility = PRIVATE, notImplemented = true)
public static IRubyObject fork(ThreadContext context, IRubyObject recv, Block block) {
return fork19(context, recv, block);
Ruby runtime = context.runtime;
throw runtime.newNotImplementedError("fork is not available on this platform");
}

@JRubyMethod(name = "fork", module = true, visibility = PRIVATE, notImplemented = true)
@Deprecated
public static IRubyObject fork19(ThreadContext context, IRubyObject recv, Block block) {
Ruby runtime = context.runtime;
throw runtime.newNotImplementedError("fork is not available on this platform");
return fork(context, recv, block);
}

@JRubyMethod(module = true)
18 changes: 8 additions & 10 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1254,7 +1254,7 @@ private static void warnMethodRemoval(final ThreadContext context, final String
* @param name The name of the method to search for
* @return The method, or UndefinedMethod if not found
*/
public DynamicMethod searchMethod(String name) {
public final DynamicMethod searchMethod(String name) {
return searchWithCache(name).method;
}

@@ -1834,11 +1834,11 @@ public boolean isMethodBound(String name, boolean checkVisibility, boolean check
return checkRespondTo ? respondsToMethod(name, checkVisibility): isMethodBound(name, checkVisibility);
}

public IRubyObject newMethod(IRubyObject receiver, String methodName, boolean bound, Visibility visibility) {
public final IRubyObject newMethod(IRubyObject receiver, String methodName, boolean bound, Visibility visibility) {
return newMethod(receiver, methodName, bound, visibility, false, true);
}

public IRubyObject newMethod(IRubyObject receiver, final String methodName, boolean bound, Visibility visibility, boolean respondToMissing) {
public final IRubyObject newMethod(IRubyObject receiver, final String methodName, boolean bound, Visibility visibility, boolean respondToMissing) {
return newMethod(receiver, methodName, bound, visibility, respondToMissing, true);
}

@@ -1875,18 +1875,15 @@ public int hashCode() {
public IRubyObject newMethod(IRubyObject receiver, final String methodName, boolean bound, Visibility visibility, boolean respondToMissing, boolean priv) {
DynamicMethod method = searchMethod(methodName);

if (method.isUndefined() ||
(visibility != null && method.getVisibility() != visibility)) {
if (method.isUndefined() || (visibility != null && method.getVisibility() != visibility)) {
if (respondToMissing) { // 1.9 behavior
if (receiver.respondsToMissing(methodName, priv)) {
method = new RespondToMissingMethod(this, PUBLIC, methodName);
} else {
throw getRuntime().newNameError("undefined method `" + methodName +
"' for class `" + this.getName() + "'", methodName);
throw getRuntime().newNameError("undefined method `" + methodName + "' for class `" + getName() + '\'', methodName);
}
} else {
throw getRuntime().newNameError("undefined method `" + methodName +
"' for class `" + this.getName() + "'", methodName);
throw getRuntime().newNameError("undefined method `" + methodName + "' for class `" + getName() + '\'', methodName);
}
}

@@ -2442,7 +2439,8 @@ public RubyArray instanceMethods(Visibility visibility, boolean includeSuper, bo
return ary;
}

final void populateInstanceMethodNames(Set<String> seen, RubyArray ary, Visibility visibility, boolean obj, boolean not, boolean recur) {
final void populateInstanceMethodNames(final Set<String> seen, final RubyArray ary, Visibility visibility,
boolean obj, boolean not, boolean recur) {
Ruby runtime = getRuntime();
RubyModule mod = this;
boolean prepended = false;
109 changes: 46 additions & 63 deletions core/src/main/java/org/jruby/RubyRandom.java
Original file line number Diff line number Diff line change
@@ -46,23 +46,20 @@ public class RubyRandom extends RubyObject {

public static class RandomType {
private final IRubyObject seed;
private final Random mt;
private final Random impl;

RandomType(Ruby runtime) {
this(randomSeed(runtime));
}
// RandomType(Ruby runtime) { this(randomSeed(runtime)); }

// c: rand_init
RandomType(IRubyObject vseed) {
this.seed = vseed.convertToInteger();
if (seed instanceof RubyFixnum) {
this.mt = randomFromFixnum((RubyFixnum) seed);
this.impl = randomFromFixnum((RubyFixnum) seed);
} else if (seed instanceof RubyBignum) {
this.mt = randomFromBignum((RubyBignum) seed);
this.impl = randomFromBignum((RubyBignum) seed);
} else {
throw vseed.getRuntime().newTypeError(
String.format("failed to convert %s into Integer", vseed.getMetaClass()
.getName()));
String.format("failed to convert %s into Integer", vseed.getMetaClass().getName()));
}
}

@@ -112,50 +109,46 @@ public static Random randomFromBigInteger(BigInteger big) {
for (int i = 0; i < ints.length; ++i) {
ints[i] = getIntBigIntegerBuffer(bytes, i);
}
this.mt = new Random(ints, left);
this.impl = new Random(ints, left);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof RandomType)) {
return false;
}
if (this == obj) return true;
if (!(obj instanceof RandomType)) return false;
RandomType rhs = (RandomType) obj;
return seed.op_equal(seed.getRuntime().getCurrentContext(), rhs.seed).isTrue()
&& mt.equals(rhs.mt);
return seed.op_equal(seed.getRuntime().getCurrentContext(), rhs.seed).isTrue() && impl.equals(rhs.impl);
}

@Override
public int hashCode() {
// Using 17 as the initializer, 37 as the multiplier.
return (629 + seed.hashCode()) * 37 + mt.hashCode();
return (629 + seed.hashCode()) * 37 + impl.hashCode();
}

RandomType(RandomType orig) {
this.seed = orig.seed;
this.mt = new Random(orig.mt);
this.impl = new Random(orig.impl);
}

int genrandInt32() {
return mt.genrandInt32();
return impl.genrandInt32();
}

double genrandReal() {
return mt.genrandReal();
return impl.genrandReal();
}

double genrandReal2() {
return mt.genrandReal2();
return impl.genrandReal2();
}

IRubyObject getSeed() {
return seed;
}

RubyBignum getState() {
int[] ints = mt.getState();
int[] ints = impl.getState();
byte[] bytes = new byte[ints.length * 4];
for (int idx = 0; idx < ints.length; ++idx) {
setIntBigIntegerBuffer(bytes, idx, ints[idx]);
@@ -164,7 +157,7 @@ RubyBignum getState() {
}

int getLeft() {
return mt.getLeft();
return impl.getLeft();
}

// big endian of bytes to reversed ints
@@ -278,14 +271,12 @@ public static IRubyObject rand(ThreadContext context, IRubyObject recv, IRubyObj
RandomType random = getDefaultRand(context);
if (args.length == 0) {
return randFloat(context, random);
} else {
return randomRand(context, args[0], random);
}
return randomRand(context, args[0], random);
}

// c: rb_f_rand for 1.9
public static IRubyObject randCommon19(ThreadContext context, IRubyObject recv,
IRubyObject[] args) {
public static IRubyObject randCommon19(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
RandomType random = getDefaultRand(context);
if (args.length == 0) {
return randFloat(context, random);
@@ -303,22 +294,6 @@ public static IRubyObject randCommon19(ThreadContext context, IRubyObject recv,
return randCommon(context, random, max);
}

// c: rb_f_rand for 1.8
public static IRubyObject randCommon18(ThreadContext context, IRubyObject recv,
IRubyObject[] args) {
RandomType random = getDefaultRand(context);
if (args.length == 0) {
return randFloat(context, random);
}
IRubyObject arg = args[0];
if (arg.isNil()) {
return randFloat(context, random);
}
// 1.8 calls rb_Integer()
RubyInteger max = (RubyInteger) RubyKernel.new_integer(context, recv, arg);
return randCommon(context, random, max);
}

private static IRubyObject randCommon(ThreadContext context, RandomType random, RubyInteger max) {
if (max.zero_p(context).isTrue()) {
return randFloat(context, random);
@@ -330,13 +305,19 @@ private static IRubyObject randCommon(ThreadContext context, RandomType random,
return r;
}

@JRubyMethod(name = "rand", optional = 1)
@Deprecated
public IRubyObject randObj(ThreadContext context, IRubyObject[] args) {
if (args.length == 0) {
return randFloat(context, random);
} else {
return randomRand(context, args[0], random);
}
return (args.length == 0) ? rand(context) : rand(context, args[0]);
}

@JRubyMethod(name = "rand")
public IRubyObject rand(ThreadContext context) {
return randFloat(context, random);
}

@JRubyMethod(name = "rand")
public IRubyObject rand(ThreadContext context, IRubyObject arg) {
return randomRand(context, arg, random);
}

// c: rand_int
@@ -376,9 +357,8 @@ public static RubyFloat randFloat(ThreadContext context, RandomType random) {

// c: limited_rand
// limited_rand gets/returns ulong but we do this in signed long only.
private static IRubyObject randLimitedFixnum(ThreadContext context, RandomType random,
long limit) {
return RubyFixnum.newFixnum(context.getRuntime(), randLimitedFixnumInner(random.mt, limit));
private static IRubyObject randLimitedFixnum(ThreadContext context, RandomType random, long limit) {
return RubyFixnum.newFixnum(context.runtime, randLimitedFixnumInner(random.impl, limit));
}

public static long randLimitedFixnumInner(Random random, long limit) {
@@ -406,8 +386,7 @@ public static long randLimitedFixnumInner(Random random, long limit) {
}

// c: limited_big_rand
private static IRubyObject randLimitedBignum(ThreadContext context, RandomType random,
RubyBignum limit) {
private static IRubyObject randLimitedBignum(ThreadContext context, RandomType random, RubyBignum limit) {
byte[] buf = limit.getBigIntegerValue().toByteArray();
byte[] bytes = new byte[buf.length];
int len = (buf.length + 3) / 4;
@@ -500,13 +479,13 @@ private static IRubyObject randomRand(ThreadContext context, IRubyObject vmax, R
double mid = 0.5;
double r;
if (Double.isInfinite(max)) {
double min = floatValue(range.begin) / 2.0;
max = floatValue(range.end) / 2.0;
double min = floatValue(context, range.begin) / 2.0;
max = floatValue(context, range.end) / 2.0;
scale = 2;
mid = max + min;
max -= min;
} else {
floatValue(v);
checkFloatValue(context, max); // v
}
v = context.nil;
if (max > 0.0) {
@@ -549,19 +528,23 @@ private static IRubyObject randomRand(ThreadContext context, IRubyObject vmax, R
}

// c: float_value
private static double floatValue(IRubyObject v) {
double x;
private static double floatValue(ThreadContext context, IRubyObject v) {
final double x;
if (v instanceof RubyFloat) {
x = ((RubyFloat) v).getDoubleValue();
} else if (v instanceof RubyNumeric) {
x = ((RubyNumeric) v).convertToFloat().getDoubleValue();
} else {
throw v.getRuntime().newTypeError(v, v.getRuntime().getFloat());
throw context.runtime.newTypeError(v, context.runtime.getFloat());
}
checkFloatValue(context, x);
return x;
}

private static void checkFloatValue(ThreadContext context, double x) {
if (Double.isInfinite(x) || Double.isNaN(x)) {
throw v.getRuntime().newErrnoEDOMError("Numerical argument out of domain");
throw context.runtime.newErrnoEDOMError("Numerical argument out of domain");
}
return x;
}

private static IRubyObject checkMaxInt(ThreadContext context, IRubyObject vmax) {
@@ -737,7 +720,7 @@ public static long randomLongLimited(ThreadContext context, IRubyObject obj, lon
return r;
}

return randLimitedFixnumInner(rnd.mt, limit);
return randLimitedFixnumInner(rnd.impl, limit);
}

// c: rb_random_real
Loading