Merge pull request #9860 from headius/merge10 · jruby/jruby@0d6ac71 · GitHub
Skip to content

Commit 0d6ac71

Browse files
authored
Merge pull request #9860 from headius/merge10
Merge 10.0 into 10.1
2 parents 6cb8735 + 1788f06 commit 0d6ac71

20 files changed

Lines changed: 259 additions & 56 deletions

File tree

‎core/pom.rb‎

Lines changed: 4 additions & 4 deletions

‎core/pom.xml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ DO NOT MODIFY - GENERATED CODE
8989
<dependency>
9090
<groupId>com.github.jnr</groupId>
9191
<artifactId>jnr-enxio</artifactId>
92-
<version>0.33.3</version>
92+
<version>0.33.4</version>
9393
<exclusions>
9494
<exclusion>
9595
<groupId>com.github.jnr</groupId>
@@ -100,7 +100,7 @@ DO NOT MODIFY - GENERATED CODE
100100
<dependency>
101101
<groupId>com.github.jnr</groupId>
102102
<artifactId>jnr-unixsocket</artifactId>
103-
<version>0.39.5</version>
103+
<version>0.39.6</version>
104104
<exclusions>
105105
<exclusion>
106106
<groupId>com.github.jnr</groupId>
@@ -111,7 +111,7 @@ DO NOT MODIFY - GENERATED CODE
111111
<dependency>
112112
<groupId>com.github.jnr</groupId>
113113
<artifactId>jnr-posix</artifactId>
114-
<version>3.2.4</version>
114+
<version>3.2.5</version>
115115
<exclusions>
116116
<exclusion>
117117
<groupId>com.github.jnr</groupId>
@@ -133,7 +133,7 @@ DO NOT MODIFY - GENERATED CODE
133133
<dependency>
134134
<groupId>com.github.jnr</groupId>
135135
<artifactId>jnr-ffi</artifactId>
136-
<version>2.3.3</version>
136+
<version>2.3.4</version>
137137
</dependency>
138138
<dependency>
139139
<groupId>com.github.jnr</groupId>

‎core/src/main/java/org/jruby/RubyArgsFile.java‎

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,18 @@ private static IRubyObject argf_getline(ThreadContext context, final int callInf
381381
while (true) {
382382
if (!data.next_argv(context)) return context.nil;
383383

384-
RubyIO currentFile = (RubyIO) data.currentFile;
385-
386384
if (isGenericInput(context, data)) {
387385
context.callInfo = callInfo; // restore callInfo for kwargs
388-
line = data.currentFile.callMethod(context, "gets", args);
386+
line = sites(context).gets.call(context, argsFile(context), data.currentFile, args);
387+
388+
// An IO updates the line number itself, but other objects do not
389+
if (!line.isNil() && !(data.currentFile instanceof RubyIO)) {
390+
context.runtime.setCurrentLine(context.runtime.getCurrentLine() + 1);
391+
}
389392
} else {
393+
// $stdin may be any object with gets (e.g. StringIO), so only cast once we know it is not generic input
394+
RubyIO currentFile = (RubyIO) data.currentFile;
395+
390396
if (args.length == 0 && context.runtime.getRecordSeparatorVar().get() == globalVariables(context).getDefaultSeparator()) {
391397
line = (currentFile).gets(context);
392398
} else {
@@ -416,38 +422,48 @@ private static boolean isGenericInput(ThreadContext context, ArgsFileData data)
416422
/** Read a line.
417423
*
418424
*/
419-
@JRubyMethod(name = "gets", optional = 1, keywords = true, checkArity = false, writes = LASTLINE)
425+
@JRubyMethod(name = "gets", optional = 2, keywords = true, checkArity = false, writes = LASTLINE)
420426
public static IRubyObject gets(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
421427
final int callInfo = ThreadContext.resetCallInfo(context);
422-
Arity.checkArgumentCount(context, args, 0, 1);
428+
checkGetlineArity(context, callInfo, args);
423429

424430
return context.setLastLine(argf_getline(context, callInfo, args));
425431
}
426432

427433
/** Read a line.
428434
*
429435
*/
430-
@JRubyMethod(name = "readline", optional = 1, keywords = true, checkArity = false, writes = LASTLINE)
436+
@JRubyMethod(name = "readline", optional = 2, keywords = true, checkArity = false, writes = LASTLINE)
431437
public static IRubyObject readline(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
438+
final int callInfo = ThreadContext.resetCallInfo(context);
439+
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);
440+
441+
// MRI: argf_readline forwards to $stdin.readline when $stdin is not an IO
442+
if (data.next_argv(context) && !(data.currentFile instanceof RubyIO)) {
443+
context.callInfo = callInfo; // restore callInfo for kwargs
444+
return sites(context).readline.call(context, recv, data.currentFile, args);
445+
}
446+
447+
context.callInfo = callInfo; // restore callInfo for kwargs
432448
IRubyObject line = gets(context, recv, args);
433449

434450
if (line.isNil()) throw context.runtime.newEOFError();
435451

436452
return line;
437453
}
438454

439-
@JRubyMethod(optional = 1, keywords = true, checkArity = false)
455+
@JRubyMethod(optional = 2, keywords = true, checkArity = false)
440456
public static IRubyObject readlines(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
441457
final int callInfo = ThreadContext.resetCallInfo(context);
442-
Arity.checkArgumentCount(context, args, 0, 1);
458+
checkGetlineArity(context, callInfo, args);
443459

444460
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);
445461

446462
if (!data.next_argv(context)) return newEmptyArray(context);
447463

448464
if (!(data.currentFile instanceof RubyIO)) {
449-
// TODO do we need to restore callInfo here?
450-
return data.currentFile.callMethod(context, "readlines", args);
465+
context.callInfo = callInfo; // restore callInfo for kwargs
466+
return sites(context).readlines.call(context, recv, data.currentFile, args);
451467
}
452468

453469
var ary = newArray(context);
@@ -458,21 +474,15 @@ public static IRubyObject readlines(ThreadContext context, IRubyObject recv, IRu
458474
return ary;
459475
}
460476

461-
@JRubyMethod(optional = 1, checkArity = false)
477+
// MRI: to_a is an alias of readlines
478+
@JRubyMethod(optional = 2, keywords = true, checkArity = false)
462479
public static IRubyObject to_a(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
463-
Arity.checkArgumentCount(context, args, 0, 1);
464-
465-
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);
466-
467-
if (!data.next_argv(context)) return newEmptyArray(context);
468-
if (!(data.currentFile instanceof RubyIO)) return data.currentFile.callMethod(context, "to_a", args);
480+
return readlines(context, recv, args);
481+
}
469482

470-
var ary = newArray(context);
471-
IRubyObject line;
472-
while ((line = argf_getline(context, 0, args)) != context.nil) {
473-
ary.append(context, line);
474-
}
475-
return ary;
483+
// MRI: rb_io_getline takes up to two positional arguments (separator, limit) plus keywords
484+
private static void checkGetlineArity(ThreadContext context, int callInfo, IRubyObject[] args) {
485+
Arity.checkArgumentCount(context, args.length - (hasKeywords(callInfo) ? 1 : 0), 0, 2);
476486
}
477487

478488
@JRubyMethod
@@ -570,21 +580,25 @@ public static IRubyObject codepoints(ThreadContext context, IRubyObject recv, Bl
570580
/** Invoke a block for each line.
571581
*
572582
*/
573-
@JRubyMethod(name = "each_line", optional = 1, keywords = true, checkArity = false)
583+
@JRubyMethod(name = "each_line", optional = 2, keywords = true, checkArity = false)
574584
public static IRubyObject each_line(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
575-
if (!block.isGiven()) return enumeratorize(context.runtime, recv, "each_line", args);
576-
577585
final int callInfo = ThreadContext.resetCallInfo(context);
578-
Arity.checkArgumentCount(context, args, 0, 1);
586+
if (!block.isGiven()) return enumeratorize(context.runtime, recv, "each_line", args, hasKeywords(callInfo));
587+
588+
return eachLineCommon(context, recv, callInfo, args, block);
589+
}
590+
591+
private static IRubyObject eachLineCommon(ThreadContext context, IRubyObject recv, int callInfo, IRubyObject[] args, Block block) {
592+
checkGetlineArity(context, callInfo, args);
579593

580594
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);
581595

582596
if (!data.next_argv(context)) return context.nil;
583597

598+
// MRI: argf_each_line calls each_line on the current file with the same arguments
584599
if (!(data.currentFile instanceof RubyIO)) {
585-
if (!data.next_argv(context)) return recv;
586-
587-
data.currentFile.callMethod(context, "each", NULL_ARRAY, block);
600+
context.callInfo = callInfo; // restore callInfo for kwargs
601+
data.currentFile.callMethod(context, "each_line", args, block);
588602
data.next_p = NextFile;
589603
}
590604

@@ -602,9 +616,12 @@ public static IRubyObject lines(ThreadContext context, IRubyObject recv, IRubyOb
602616
return each_line(context, recv, args, block);
603617
}
604618

605-
@JRubyMethod(name = "each", optional = 1, checkArity = false)
619+
@JRubyMethod(name = "each", optional = 2, keywords = true, checkArity = false)
606620
public static IRubyObject each(final ThreadContext context, IRubyObject recv, IRubyObject[] args, final Block block) {
607-
return block.isGiven() ? each_line(context, recv, args, block) : enumeratorize(context.runtime, recv, "each", args);
621+
final int callInfo = ThreadContext.resetCallInfo(context);
622+
if (!block.isGiven()) return enumeratorize(context.runtime, recv, "each", args, hasKeywords(callInfo));
623+
624+
return eachLineCommon(context, recv, callInfo, args, block);
608625
}
609626

610627
@JRubyMethod(name = "file")

‎core/src/main/java/org/jruby/RubyEnumerator.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ public static IRubyObject enumeratorize(Ruby runtime, IRubyObject object, String
198198
return new RubyEnumerator(runtime, runtime.getEnumerator(), object, runtime.fastNewSymbol(method), args);
199199
}
200200

201+
/**
202+
* Like {@link #enumeratorize(Ruby, IRubyObject, String, IRubyObject...)}, but if keywords is true the last
203+
* element of args is passed back to the method as keywords.
204+
*/
205+
public static IRubyObject enumeratorize(Ruby runtime, IRubyObject object, String method, IRubyObject[] args, boolean keywords) {
206+
return new RubyEnumerator(runtime, runtime.getEnumerator(), object, runtime.fastNewSymbol(method), args, null, null, keywords);
207+
}
208+
201209
public static IRubyObject enumeratorize(Ruby runtime, RubyClass type, IRubyObject object, String method) {
202210
return new RubyEnumerator(runtime, type, object, runtime.fastNewSymbol(method), NULL_ARRAY);
203211
}

‎core/src/main/java/org/jruby/RubyIO.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3892,23 +3892,23 @@ public IRubyObject each(final ThreadContext context, final Block block) {
38923892
@JRubyMethod(keywords = true)
38933893
public IRubyObject each(final ThreadContext context, IRubyObject arg0, final Block block) {
38943894
boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context));
3895-
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each");
3895+
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each", new IRubyObject[] { arg0 }, keywords);
38963896

38973897
return Getline.getlineCall(context, GETLINE_YIELD, this, getReadEncoding(context), arg0, block, keywords);
38983898
}
38993899

39003900
@JRubyMethod(keywords = true)
39013901
public IRubyObject each(final ThreadContext context, IRubyObject arg0, IRubyObject arg1, final Block block) {
39023902
boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context));
3903-
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each");
3903+
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each", new IRubyObject[] { arg0, arg1 }, keywords);
39043904

39053905
return Getline.getlineCall(context, GETLINE_YIELD, this, getReadEncoding(context), arg0, arg1, block, keywords);
39063906
}
39073907

39083908
@JRubyMethod(keywords = true)
39093909
public IRubyObject each(final ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, final Block block) {
39103910
boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context));
3911-
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each");
3911+
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each", new IRubyObject[] { arg0, arg1, arg2 }, keywords);
39123912

39133913
return Getline.getlineCall(context, GETLINE_YIELD, this, getReadEncoding(context), arg0, arg1, arg2, block, keywords);
39143914
}
@@ -3940,7 +3940,7 @@ public IRubyObject each_line(final ThreadContext context, final Block block) {
39403940
public IRubyObject each_line(final ThreadContext context, IRubyObject arg0, final Block block) {
39413941
boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context));
39423942

3943-
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_line", arg0);
3943+
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_line", new IRubyObject[] { arg0 }, keywords);
39443944

39453945
return Getline.getlineCall(context, GETLINE_YIELD, this, getReadEncoding(context), arg0, block, keywords);
39463946
}
@@ -3949,7 +3949,7 @@ public IRubyObject each_line(final ThreadContext context, IRubyObject arg0, fina
39493949
public IRubyObject each_line(final ThreadContext context, IRubyObject arg0, IRubyObject arg1, final Block block) {
39503950
boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context));
39513951

3952-
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_line", arg0, arg1);
3952+
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_line", new IRubyObject[] { arg0, arg1 }, keywords);
39533953

39543954
return Getline.getlineCall(context, GETLINE_YIELD, this, getReadEncoding(context), arg0, arg1, block, keywords);
39553955
}
@@ -3958,7 +3958,7 @@ public IRubyObject each_line(final ThreadContext context, IRubyObject arg0, IRub
39583958
public IRubyObject each_line(final ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, final Block block) {
39593959
boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context));
39603960

3961-
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_line", arg0, arg1, arg2);
3961+
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_line", new IRubyObject[] { arg0, arg1, arg2 }, keywords);
39623962

39633963
return Getline.getlineCall(context, GETLINE_YIELD, this, getReadEncoding(context), arg0, arg1, arg2, block, keywords);
39643964
}
@@ -4081,7 +4081,7 @@ public static IRubyObject foreach(final ThreadContext context, IRubyObject recv,
40814081

40824082
Arity.checkArgumentCount(context, args.length - (keywords ? 1 : 0), 1, 4);
40834083

4084-
if (!block.isGiven()) return enumeratorize(context.runtime, recv, "foreach", args);
4084+
if (!block.isGiven()) return enumeratorize(context.runtime, recv, "foreach", args, keywords);
40854085

40864086
return foreachInternal(context, recv, args, keywords, block);
40874087
}

‎core/src/main/java/org/jruby/RubyKernel.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,14 @@ public static IRubyObject printf(ThreadContext context, IRubyObject recv, IRubyO
810810
return context.nil;
811811
}
812812

813+
// MRI: rb_f_readline
813814
@JRubyMethod(optional = 1, keywords = true, checkArity = false, module = true, visibility = PRIVATE)
814815
public static IRubyObject readline(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
815-
IRubyObject line = gets(context, recv, args);
816-
817-
if (line.isNil()) {
818-
throw context.runtime.newEOFError();
819-
}
816+
var ArgsFile = argsFile(context);
820817

821-
return line;
818+
return recv == ArgsFile ?
819+
RubyArgsFile.readline(context, ArgsFile, args) :
820+
sites(context).readline.call(context, ArgsFile, ArgsFile, args);
822821
}
823822

824823
@JRubyMethod(optional = 1, keywords = true, checkArity = false, module = true, visibility = PRIVATE)

‎core/src/main/java/org/jruby/ir/targets/JVM.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public MethodData methodData() {
4545

4646
public void pushscript(JVMVisitor visitor, String clsName, String filename) {
4747
writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
48+
49+
// The maxBytes and maxOperations limits are raised from 10MB and 100M ops to allow very large methods.
50+
// This limit does not override Options.JIT_MAXSIZE and is only used for exercising the JIT.
51+
writer.setComputeLimits(20_000_000, 400_000_000);
52+
4853
classStack.push(new ClassData(clsName, writer, visitor));
4954

5055
cls().visit(RubyInstanceConfig.JAVA_VERSION, ACC_PUBLIC + ACC_SUPER, clsName, null, p(Object.class), null);

‎core/src/main/java/org/jruby/runtime/JavaSites.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.jruby.runtime.callsite.DivCallSite;
88
import org.jruby.runtime.callsite.FunctionalCachingCallSite;
99
import org.jruby.runtime.callsite.MulCallSite;
10+
import org.jruby.runtime.callsite.MonomorphicCallSite;
1011
import org.jruby.runtime.callsite.PlusCallSite;
1112
import org.jruby.runtime.callsite.RespondToCallSite;
1213
import org.jruby.runtime.callsite.SuperCallSite;
@@ -97,6 +98,7 @@ public static class KernelSites {
9798
public final CallSite to_str = new FunctionalCachingCallSite("to_str");
9899
public final CallSite getc = new FunctionalCachingCallSite("getc");
99100
public final CallSite gets = new FunctionalCachingCallSite("gets");
101+
public final CallSite readline = new FunctionalCachingCallSite("readline");
100102
public final CallSite putc = new FunctionalCachingCallSite("putc");
101103
public final CallSite puts = new FunctionalCachingCallSite("puts");
102104
public final CallSite initialize_copy = new FunctionalCachingCallSite("initialize_copy");
@@ -488,6 +490,11 @@ public static class ZlibSites {
488490

489491
public static class ArgfSites {
490492
public final CallSite each_codepoint = new FunctionalCachingCallSite("each_codepoint");
493+
// MRI: forward_current calls only public methods on $stdin (rb_funcallv_public_kw). A functional call
494+
// would reach the private Kernel#gets etc. on a plain object, which read from ARGF again and recurse.
495+
public final CallSite gets = new MonomorphicCallSite("gets");
496+
public final CallSite readline = new MonomorphicCallSite("readline");
497+
public final CallSite readlines = new MonomorphicCallSite("readlines");
491498
}
492499

493500
public static class TracePointSites {

‎pom.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
# used in ./lib/pom.rb and ./maven/jruby-stdlib/pom.rb
7474
"rake.version": '13.4.2',
7575
"jruby-launcher.version": '1.1.6',
76-
"asm.version": '9.10.1',
76+
"asm.version": '9.11.1',
7777
"jar-dependencies.version": '0.4.1',
7878
"jffi.version": '1.4.3',
7979
"joda.time.version": '2.14.0')

‎pom.xml‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)