Skip to content

Commit

Permalink
Update logic for Numeric#step from MRI 2.5. Fixes #5078
Browse files Browse the repository at this point in the history
This includes the following changes:

* Re-port Numeric#step logic and related functions.
* Re-port Numeric#step enumerator size logic.
* Modify ArgsUtil.extractKeywordArgs to use UNDEF instead of nil.
* Update tags for Numeric, Fixnum, Bignum, Integer, Float (no
  changes for last two).
headius committed Apr 12, 2018
1 parent 79e9b26 commit 73808fb
Showing 7 changed files with 196 additions and 163 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -4040,7 +4040,7 @@ public IRubyObject shuffle_bang(ThreadContext context, IRubyObject[] args) {
IRubyObject hash = TypeConverter.checkHashType(context.runtime, args[args.length - 1]);
if (!hash.isNil()) {
IRubyObject[] rets = ArgsUtil.extractKeywordArgs(context, (RubyHash) hash, new String[] { "random" });
if (!rets[0].isNil()) randgen = rets[0];
if (rets[0] != UNDEF) randgen = rets[0];
}
}
int i = realLength;
@@ -4081,7 +4081,7 @@ public IRubyObject sample(ThreadContext context, IRubyObject[] args) {
IRubyObject hash = TypeConverter.checkHashType(context.runtime, args[args.length - 1]);
if (!hash.isNil()) {
IRubyObject[] rets = ArgsUtil.extractKeywordArgs(context, (RubyHash) hash, new String[] { "random" });
if (!rets[0].isNil()) randgen = rets[0];
if (rets[0] != UNDEF) randgen = rets[0];
args = ArraySupport.newCopy(args, args.length - 1);
}
}
304 changes: 189 additions & 115 deletions core/src/main/java/org/jruby/RubyNumeric.java

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ast/util/ArgsUtil.java
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyBasicObject;
import org.jruby.RubyHash;
import org.jruby.RubySymbol;
import org.jruby.runtime.ThreadContext;
@@ -118,7 +119,7 @@ public static IRubyObject[] extractKeywordArgs(ThreadContext context, RubyHash o
if (options.containsKey(keySym)) {
ret[index] = options.fastARef(keySym);
} else {
ret[index] = context.runtime.getNil();
ret[index] = RubyBasicObject.UNDEF;
}
index++;
validKeySet.add(keySym);
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -160,8 +160,9 @@ public static class NumericSites {
public final CallSite div = new FunctionalCachingCallSite("div");
public final CallSite op_times = new FunctionalCachingCallSite("*");
public final CallSite op_mod = new FunctionalCachingCallSite("%");
public final CallSite op_lt = new FunctionalCachingCallSite("<");
public final CallSite op_gt = new FunctionalCachingCallSite(">");
public final CachingCallSite op_lt = new FunctionalCachingCallSite("<");
public final CachingCallSite op_gt = new FunctionalCachingCallSite(">");
public final CheckedSites op_gt_checked = new CheckedSites(">");
public final CallSite op_uminus = new FunctionalCachingCallSite("-@");
public final CallSite zero = new FunctionalCachingCallSite("zero?");
public final CallSite op_equals = new FunctionalCachingCallSite("==");
1 change: 0 additions & 1 deletion spec/tags/ruby/core/fixnum/bit_length_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/ruby/core/numeric/modulo_tags.txt

This file was deleted.

41 changes: 0 additions & 41 deletions spec/tags/ruby/core/numeric/step_tags.txt
Original file line number Diff line number Diff line change
@@ -20,50 +20,9 @@ fails:Numeric#step with keyword arguments when step is a String with self and st
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an when step is a numeric representation
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an with step as an alphanumeric string
fails:Numeric#step with mixed arguments should loop over self when step is 0 or 0.0
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums yields only Fixnums
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a positive step yields while increasing self by step until stop is reached
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a positive step yields once when self equals stop
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a positive step does not yield when self is greater than stop
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a negative step yields while decreasing self by step until stop is reached
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a negative step yields once when self equals stop
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a negative step does not yield when self is less than stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float yields Floats even if only self is a Float
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float yields Floats even if only stop is a Float
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float yields Floats even if only step is a Float
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive step yields while increasing self by step while < stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive step yields once when self equals stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive step does not yield when self is greater than stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive step is careful about not yielding a value greater than limit
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative step yields while decreasing self by step while self > stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative step yields once when self equals stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative step does not yield when self is less than stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative step is careful about not yielding a value smaller than limit
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once if self < stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once when stop is Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once when self equals stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step does not yield when self > stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step does not yield when stop is -Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once if self > stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once if stop is -Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once when self equals stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step does not yield when self > stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step does not yield when stop is Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a Infinity stop and a negative step does not yield when self is positive infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity stop and a positive step does not yield when self is negative infinity
fails:Numeric#step with mixed arguments when no block is given returns an Enumerator that uses the given step
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is positive returns the difference between self and stop divided by the number of steps
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is positive returns 0 if value > limit
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is negative returns the difference between self and stop divided by the number of steps
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is negative returns 0 if value < limit
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is positive returns the difference between self and stop divided by the number of steps
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is positive returns 0 if value > limit
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is negative returns the difference between self and stop divided by the number of steps
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is negative returns 0 if value < limit
fails:Numeric#step with positional args when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
fails:Numeric#step with positional args when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string
fails:Numeric#step with positional args when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
fails:Numeric#step with positional args when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string
fails:Numeric#step with keyword arguments when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
fails:Numeric#step with keyword arguments when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError when step is a numeric representation
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an ArgumentError with step as an alphanumeric string

0 comments on commit 73808fb

Please sign in to comment.