Skip to content

Commit fdbbe97

Browse files
committedFeb 23, 2018
Merge branch 'master' into ruby-2.5
2 parents 5af83bd + 0f3746b commit fdbbe97

26 files changed

+647
-417
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/Ruby.java

+23-3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080

8181
import org.jcodings.Encoding;
8282
import org.joda.time.DateTimeZone;
83+
import org.joni.WarnCallback;
8384
import org.jruby.ast.Node;
8485
import org.jruby.ast.RootNode;
8586
import org.jruby.ast.executable.RuntimeCache;
@@ -2847,6 +2848,10 @@ public RubyWarnings getWarnings() {
28472848
return warnings;
28482849
}
28492850

2851+
WarnCallback getRegexpWarnings() {
2852+
return regexpWarnings;
2853+
}
2854+
28502855
public PrintStream getErrorStream() {
28512856
// FIXME: We can't guarantee this will always be a RubyIO...so the old code here is not safe
28522857
/*java.io.OutputStream os = ((RubyIO) getGlobalVariables().getService("$stderr")).getOutStream();
@@ -3030,13 +3035,23 @@ public void addBoundMethod(String className, String methodName, String rubyName)
30303035
javaToRuby.put(methodName, rubyName);
30313036
}
30323037

3038+
public void addBoundMethods(String className, String... tuples) {
3039+
Map<String, String> javaToRuby = boundMethods.get(className);
3040+
if (javaToRuby == null) boundMethods.put(className, javaToRuby = new HashMap<>(tuples.length / 2 + 1, 1));
3041+
for (int i = 0; i < tuples.length; i += 2) {
3042+
javaToRuby.put(tuples[i], tuples[i+1]);
3043+
}
3044+
}
3045+
3046+
@Deprecated // no longer used -> except for IndyBinder
30333047
public void addBoundMethodsPacked(String className, String packedTuples) {
30343048
List<String> names = StringSupport.split(packedTuples, ';');
30353049
for (int i = 0; i < names.size(); i += 2) {
30363050
addBoundMethod(className, names.get(i), names.get(i+1));
30373051
}
30383052
}
30393053

3054+
@Deprecated // no longer used -> except for IndyBinder
30403055
public void addSimpleBoundMethodsPacked(String className, String packedNames) {
30413056
List<String> names = StringSupport.split(packedNames, ';');
30423057
for (String name : names) {
@@ -4502,8 +4517,7 @@ public List<StrptimeToken> getCachedStrptimePattern(String pattern) {
45024517
* @param method
45034518
*/
45044519
void addProfiledMethod(final String name, final DynamicMethod method) {
4505-
if (!config.isProfiling()) return;
4506-
if (method.isUndefined()) return;
4520+
if (!config.isProfiling() || method.isUndefined()) return;
45074521

45084522
getProfilingService().addProfiledMethod( name, method );
45094523
}
@@ -5007,7 +5021,7 @@ private MRIRecursionGuard oldRecursionGuard() {
50075021

50085022
private final long startTime = System.currentTimeMillis();
50095023

5010-
private final RubyInstanceConfig config;
5024+
final RubyInstanceConfig config;
50115025

50125026
private InputStream in;
50135027
private PrintStream out;
@@ -5058,6 +5072,12 @@ private MRIRecursionGuard oldRecursionGuard() {
50585072

50595073
private GlobalVariables globalVariables = new GlobalVariables(this);
50605074
private final RubyWarnings warnings = new RubyWarnings(this);
5075+
private final WarnCallback regexpWarnings = new WarnCallback() {
5076+
@Override
5077+
public void warn(String message) {
5078+
getWarnings().warning(message);
5079+
}
5080+
};
50615081

50625082
// Contains a list of all blocks (as Procs) that should be called when
50635083
// the runtime environment exits.

Diff for: ‎core/src/main/java/org/jruby/RubyBasicObject.java

+39-45
Original file line numberDiff line numberDiff line change
@@ -1743,50 +1743,6 @@ public IRubyObject send(ThreadContext context, IRubyObject[] args, Block block)
17431743
return getMetaClass().finvoke(context, this, name, args, block);
17441744
}
17451745

1746-
@JRubyMethod(name = "instance_eval",
1747-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1748-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
1749-
public IRubyObject instance_eval19(ThreadContext context, Block block) {
1750-
return specificEval(context, getInstanceEvalClass(), block, EvalType.INSTANCE_EVAL);
1751-
}
1752-
@JRubyMethod(name = "instance_eval",
1753-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1754-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
1755-
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, Block block) {
1756-
return specificEval(context, getInstanceEvalClass(), arg0, block, EvalType.INSTANCE_EVAL);
1757-
}
1758-
@JRubyMethod(name = "instance_eval",
1759-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1760-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
1761-
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
1762-
return specificEval(context, getInstanceEvalClass(), arg0, arg1, block, EvalType.INSTANCE_EVAL);
1763-
}
1764-
@JRubyMethod(name = "instance_eval",
1765-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1766-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
1767-
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
1768-
return specificEval(context, getInstanceEvalClass(), arg0, arg1, arg2, block, EvalType.INSTANCE_EVAL);
1769-
}
1770-
1771-
@JRubyMethod(name = "instance_exec", optional = 3, rest = true,
1772-
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
1773-
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
1774-
public IRubyObject instance_exec19(ThreadContext context, IRubyObject[] args, Block block) {
1775-
if (!block.isGiven()) {
1776-
throw context.runtime.newLocalJumpErrorNoBlock();
1777-
}
1778-
1779-
RubyModule klazz;
1780-
if (isImmediate()) {
1781-
// Ruby uses Qnil here, we use "dummy" because we need a class
1782-
klazz = context.runtime.getDummy();
1783-
} else {
1784-
klazz = getSingletonClass();
1785-
}
1786-
1787-
return yieldUnder(context, klazz, args, block, EvalType.INSTANCE_EVAL);
1788-
}
1789-
17901746
/**
17911747
* Will yield to the specific block changing the self to be the
17921748
* current object instead of the self that is part of the frame
@@ -2631,19 +2587,49 @@ public RubyArray to_a() {
26312587
* k = Klass.new
26322588
* k.instance_eval { @secret } #=> 99
26332589
*/
2590+
2591+
@JRubyMethod(name = "instance_eval",
2592+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
2593+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
26342594
public IRubyObject instance_eval(ThreadContext context, Block block) {
26352595
return specificEval(context, getInstanceEvalClass(), block, EvalType.INSTANCE_EVAL);
26362596
}
2597+
@JRubyMethod(name = "instance_eval",
2598+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
2599+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
26372600
public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, Block block) {
26382601
return specificEval(context, getInstanceEvalClass(), arg0, block, EvalType.INSTANCE_EVAL);
26392602
}
2603+
@JRubyMethod(name = "instance_eval",
2604+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
2605+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
26402606
public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
26412607
return specificEval(context, getInstanceEvalClass(), arg0, arg1, block, EvalType.INSTANCE_EVAL);
26422608
}
2609+
@JRubyMethod(name = "instance_eval",
2610+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
2611+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
26432612
public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
26442613
return specificEval(context, getInstanceEvalClass(), arg0, arg1, arg2, block, EvalType.INSTANCE_EVAL);
26452614
}
26462615

2616+
@Deprecated
2617+
public IRubyObject instance_eval19(ThreadContext context, Block block) {
2618+
return specificEval(context, getInstanceEvalClass(), block, EvalType.INSTANCE_EVAL);
2619+
}
2620+
@Deprecated
2621+
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, Block block) {
2622+
return specificEval(context, getInstanceEvalClass(), arg0, block, EvalType.INSTANCE_EVAL);
2623+
}
2624+
@Deprecated
2625+
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
2626+
return specificEval(context, getInstanceEvalClass(), arg0, arg1, block, EvalType.INSTANCE_EVAL);
2627+
}
2628+
@Deprecated
2629+
public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
2630+
return specificEval(context, getInstanceEvalClass(), arg0, arg1, arg2, block, EvalType.INSTANCE_EVAL);
2631+
}
2632+
26472633
/** rb_obj_instance_exec
26482634
*
26492635
* call-seq:
@@ -2662,9 +2648,12 @@ public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyO
26622648
* k = Klass.new
26632649
* k.instance_exec(5) {|x| @secret+x } #=> 104
26642650
*/
2651+
@JRubyMethod(name = "instance_exec", optional = 3, rest = true,
2652+
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
2653+
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
26652654
public IRubyObject instance_exec(ThreadContext context, IRubyObject[] args, Block block) {
26662655
if (!block.isGiven()) {
2667-
throw context.runtime.newArgumentError("block not supplied");
2656+
throw context.runtime.newLocalJumpErrorNoBlock();
26682657
}
26692658

26702659
RubyModule klazz;
@@ -2678,6 +2667,11 @@ public IRubyObject instance_exec(ThreadContext context, IRubyObject[] args, Bloc
26782667
return yieldUnder(context, klazz, args, block, EvalType.INSTANCE_EVAL);
26792668
}
26802669

2670+
@Deprecated
2671+
public IRubyObject instance_exec19(ThreadContext context, IRubyObject[] args, Block block) {
2672+
return instance_exec(context, args, block);
2673+
}
2674+
26812675
/** rb_obj_extend
26822676
*
26832677
* call-seq:

Diff for: ‎core/src/main/java/org/jruby/RubyBignum.java

+46-26
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ public static double big2dbl(RubyBignum value) {
218218
return dbl;
219219
}
220220

221-
private IRubyObject checkShiftDown(RubyBignum other) {
222-
if (other.value.signum() == 0) return RubyFixnum.zero(getRuntime());
221+
private RubyFixnum checkShiftDown(ThreadContext context, RubyBignum other) {
222+
if (other.value.signum() == 0) return RubyFixnum.zero(context.runtime);
223223
if (value.compareTo(LONG_MIN) < 0 || value.compareTo(LONG_MAX) > 0) {
224-
return other.value.signum() >= 0 ? RubyFixnum.zero(getRuntime()) : RubyFixnum.minus_one(getRuntime());
224+
return other.value.signum() >= 0 ? RubyFixnum.zero(context.runtime) : RubyFixnum.minus_one(context.runtime);
225225
}
226-
return getRuntime().getNil();
226+
return null;
227227
}
228228

229229
/**
@@ -626,27 +626,32 @@ public IRubyObject divmod(ThreadContext context, IRubyObject other) {
626626
*/
627627
@JRubyMethod(name = {"%", "modulo"}, required = 1)
628628
public IRubyObject op_mod(ThreadContext context, IRubyObject other) {
629-
if (!other.isNil() && other instanceof RubyFloat
630-
&& ((RubyFloat)other).getDoubleValue() == 0) {
631-
throw context.runtime.newZeroDivisionError();
629+
if (other instanceof RubyFixnum) {
630+
return op_mod(context, ((RubyFixnum) other).getLongValue());
632631
}
633632

634633
final BigInteger otherValue;
635-
if (other instanceof RubyFixnum) {
636-
otherValue = fix2big((RubyFixnum) other);
637-
} else if (other instanceof RubyBignum) {
634+
if (other instanceof RubyBignum) {
638635
otherValue = ((RubyBignum) other).value;
639-
} else {
640-
if (other instanceof RubyFloat && ((RubyFloat) other).getDoubleValue() == 0) {
641-
throw context.runtime.newZeroDivisionError();
642-
}
643-
return coerceBin(context, sites(context).op_mod, other);
636+
if (otherValue.signum() == 0) throw context.runtime.newZeroDivisionError();
637+
638+
BigInteger result = value.mod(otherValue.abs());
639+
if (otherValue.signum() == -1 && result.signum() != 0) result = otherValue.add(result);
640+
return bignorm(context.runtime, result);
644641
}
645642

646-
if (otherValue.signum() == 0) throw context.runtime.newZeroDivisionError();
643+
if (other instanceof RubyFloat && ((RubyFloat) other).getDoubleValue() == 0) {
644+
throw context.runtime.newZeroDivisionError();
645+
}
646+
return coerceBin(context, sites(context).op_mod, other);
647+
}
648+
649+
@Override
650+
public IRubyObject op_mod(ThreadContext context, long other) {
651+
if (other == 0) throw context.runtime.newZeroDivisionError();
647652

648-
BigInteger result = value.mod(otherValue.abs());
649-
if (otherValue.signum() == -1 && result.signum() != 0) result = otherValue.add(result);
653+
BigInteger result = value.mod(long2big(other < 0 ? -other : other));
654+
if (other < 0 && result.signum() != 0) result = long2big(other).add(result);
650655
return bignorm(context.runtime, result);
651656
}
652657

@@ -850,13 +855,13 @@ public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
850855

851856
for (;;) {
852857
if (other instanceof RubyFixnum) {
853-
shift = ((RubyFixnum)other).getLongValue();
858+
shift = ((RubyFixnum) other).getLongValue();
854859
break;
855860
} else if (other instanceof RubyBignum) {
856-
RubyBignum otherBignum = (RubyBignum)other;
861+
RubyBignum otherBignum = (RubyBignum) other;
857862
if (otherBignum.value.signum() < 0) {
858-
IRubyObject tmp = otherBignum.checkShiftDown(this);
859-
if (!tmp.isNil()) return tmp;
863+
IRubyObject tmp = otherBignum.checkShiftDown(context, this);
864+
if (tmp != null) return tmp;
860865
}
861866
shift = big2long(otherBignum);
862867
break;
@@ -876,13 +881,13 @@ public IRubyObject op_rshift(ThreadContext context, IRubyObject other) {
876881

877882
for (;;) {
878883
if (other instanceof RubyFixnum) {
879-
shift = ((RubyFixnum)other).getLongValue();
884+
shift = ((RubyFixnum) other).getLongValue();
880885
break;
881886
} else if (other instanceof RubyBignum) {
882-
RubyBignum otherBignum = (RubyBignum)other;
887+
RubyBignum otherBignum = (RubyBignum) other;
883888
if (otherBignum.value.signum() >= 0) {
884-
IRubyObject tmp = otherBignum.checkShiftDown(this);
885-
if (!tmp.isNil()) return tmp;
889+
IRubyObject tmp = otherBignum.checkShiftDown(context, this);
890+
if (tmp != null) return tmp;
886891
}
887892
shift = big2long(otherBignum);
888893
break;
@@ -1177,6 +1182,21 @@ public boolean isImmediate() {
11771182
return true;
11781183
}
11791184

1185+
@Override
1186+
public IRubyObject numerator(ThreadContext context) {
1187+
return this;
1188+
}
1189+
1190+
@Override
1191+
public IRubyObject denominator(ThreadContext context) {
1192+
return RubyFixnum.one(context.runtime);
1193+
}
1194+
1195+
public RubyRational convertToRational() {
1196+
final Ruby runtime = getRuntime();
1197+
return RubyRational.newRationalRaw(runtime, this, RubyFixnum.one(runtime));
1198+
}
1199+
11801200
private static JavaSites.BignumSites sites(ThreadContext context) {
11811201
return context.sites.Bignum;
11821202
}

Diff for: ‎core/src/main/java/org/jruby/RubyFixnum.java

+34-2
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ public IRubyObject op_mod(ThreadContext context, IRubyObject other) {
730730
return coerceBin(context, sites(context).op_mod, other);
731731
}
732732

733+
@Override
733734
public IRubyObject op_mod(ThreadContext context, long other) {
734735
return moduloFixnum(context, other);
735736
}
@@ -846,13 +847,13 @@ private IRubyObject powerOther(ThreadContext context, IRubyObject other) {
846847
return coerceBin(context, sites(context).op_exp, other);
847848
}
848849

849-
private IRubyObject powerFixnum(ThreadContext context, RubyFixnum other) {
850+
private RubyNumeric powerFixnum(ThreadContext context, RubyFixnum other) {
850851
Ruby runtime = context.runtime;
851852
long a = value;
852853
long b = other.value;
853854
if (b < 0) {
854855
RubyRational rational = RubyRational.newRationalRaw(runtime, this);
855-
return numFuncall(context, rational, sites(context).op_exp_rational, other);
856+
return (RubyNumeric) numFuncall(context, rational, sites(context).op_exp_rational, other);
856857
}
857858
if (b == 0) {
858859
return RubyFixnum.one(runtime);
@@ -1363,6 +1364,37 @@ protected boolean int_round_zero_p(ThreadContext context, int ndigits) {
13631364
return (-0.415241 * ndigits - 0.125 > bytes);
13641365
}
13651366

1367+
@Override
1368+
public IRubyObject numerator(ThreadContext context) {
1369+
return this;
1370+
}
1371+
1372+
@Override
1373+
public IRubyObject denominator(ThreadContext context) {
1374+
return one(context.runtime);
1375+
}
1376+
1377+
public RubyRational convertToRational() {
1378+
final Ruby runtime = getRuntime();
1379+
return RubyRational.newRationalRaw(runtime, this, one(runtime));
1380+
}
1381+
1382+
@Override
1383+
public IRubyObject remainder(ThreadContext context, IRubyObject y) {
1384+
RubyFixnum x = this;
1385+
JavaSites.FixnumSites sites = sites(context);
1386+
IRubyObject z = sites.op_mod.call(context, this, this, y);
1387+
1388+
if ((!Helpers.rbEqual(context, z, RubyFixnum.zero(context.runtime), sites.op_equal).isTrue()) &&
1389+
((x.isNegative() &&
1390+
((RubyInteger) y).isPositive()) ||
1391+
(x.isPositive() &&
1392+
((RubyInteger) y).isNegative()))) {
1393+
return sites.op_minus.call(context, z, z, y);
1394+
}
1395+
return z;
1396+
}
1397+
13661398
private static JavaSites.FixnumSites sites(ThreadContext context) {
13671399
return context.sites.Fixnum;
13681400
}

0 commit comments

Comments
 (0)
Please sign in to comment.