Skip to content

Commit a8a7fe3

Browse files
committed
Merge remote-tracking branch 'origin/jruby-10.0'
2 parents 136b933 + 574c478 commit a8a7fe3

20 files changed

Lines changed: 504 additions & 109 deletions

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

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@
7878
import static org.jruby.api.Define.defineClass;
7979
import static org.jruby.api.Error.argumentError;
8080
import static org.jruby.api.Warn.warn;
81-
import static org.jruby.runtime.ThreadContext.CALL_KEYWORD;
82-
import static org.jruby.runtime.ThreadContext.resetCallInfo;
81+
import static org.jruby.runtime.ThreadContext.hasKeywords;
8382
import static org.jruby.runtime.Visibility.PRIVATE;
8483

8584
public class RubyArgsFile extends RubyObject {
@@ -374,9 +373,7 @@ public static IRubyObject external_encoding(ThreadContext context, IRubyObject r
374373
}
375374

376375
// MRI: argf_getline
377-
private static IRubyObject argf_getline(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
378-
int callInfo = resetCallInfo(context);
379-
boolean keywords = (callInfo & CALL_KEYWORD) != 0;
376+
private static IRubyObject argf_getline(ThreadContext context, final int callInfo, IRubyObject[] args) {
380377
IRubyObject line;
381378
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);
382379

@@ -386,14 +383,13 @@ private static IRubyObject argf_getline(ThreadContext context, IRubyObject recv,
386383
RubyIO currentFile = (RubyIO) data.currentFile;
387384

388385
if (isGenericInput(context, data)) {
389-
// restore callInfo for kwargs
390-
context.callInfo = callInfo;
386+
context.callInfo = callInfo; // restore callInfo for kwargs
391387
line = data.currentFile.callMethod(context, "gets", args);
392388
} else {
393389
if (args.length == 0 && context.runtime.getRecordSeparatorVar().get() == globalVariables(context).getDefaultSeparator()) {
394390
line = (currentFile).gets(context);
395391
} else {
396-
line = Getline.getlineCall(context, GETLINE, currentFile, currentFile.getReadEncoding(), keywords, args);
392+
line = Getline.getlineCall(context, GETLINE, currentFile, currentFile.getReadEncoding(), hasKeywords(callInfo), args);
397393
}
398394

399395
if (line.isNil() && data.next_p != Stream) {
@@ -421,9 +417,10 @@ private static boolean isGenericInput(ThreadContext context, ArgsFileData data)
421417
*/
422418
@JRubyMethod(name = "gets", optional = 1, keywords = true, checkArity = false, writes = LASTLINE)
423419
public static IRubyObject gets(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
420+
final int callInfo = ThreadContext.resetCallInfo(context);
424421
Arity.checkArgumentCount(context, args, 0, 1);
425422

426-
return context.setLastLine(argf_getline(context, recv, args));
423+
return context.setLastLine(argf_getline(context, callInfo, args));
427424
}
428425

429426
/** Read a line.
@@ -440,36 +437,26 @@ public static IRubyObject readline(ThreadContext context, IRubyObject recv, IRub
440437

441438
@JRubyMethod(optional = 1, keywords = true, checkArity = false)
442439
public static IRubyObject readlines(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
440+
final int callInfo = ThreadContext.resetCallInfo(context);
443441
Arity.checkArgumentCount(context, args, 0, 1);
444442

445-
int callInfo = context.callInfo;
446443
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);
447444

448445
if (!data.next_argv(context)) return newEmptyArray(context);
449446

450-
if (!(data.currentFile instanceof RubyIO)) return data.currentFile.callMethod(context, "readlines", args);
447+
if (!(data.currentFile instanceof RubyIO)) {
448+
// TODO do we need to restore callInfo here?
449+
return data.currentFile.callMethod(context, "readlines", args);
450+
}
451451

452452
var ary = newArray(context);
453453
IRubyObject line;
454-
while(!(line = argfGetlineLoopWithKeywords(context, recv, args, callInfo)).isNil()) {
454+
while(!(line = argf_getline(context, callInfo, args)).isNil()) {
455455
ary.append(context, line);
456456
}
457457
return ary;
458458
}
459459

460-
/**
461-
* Call argf_getline as in a loop, providing the given keywords state between calls.
462-
*
463-
* @param context
464-
* @param recv
465-
* @param args
466-
* @return
467-
*/
468-
private static IRubyObject argfGetlineLoopWithKeywords(ThreadContext context, IRubyObject recv, IRubyObject[] args, int callInfo) {
469-
context.callInfo = callInfo;
470-
return argf_getline(context, recv, args);
471-
}
472-
473460
@JRubyMethod(optional = 1, checkArity = false)
474461
public static IRubyObject to_a(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
475462
Arity.checkArgumentCount(context, args, 0, 1);
@@ -481,7 +468,7 @@ public static IRubyObject to_a(ThreadContext context, IRubyObject recv, IRubyObj
481468

482469
var ary = newArray(context);
483470
IRubyObject line;
484-
while ((line = argf_getline(context, recv, args)) != context.nil) {
471+
while ((line = argf_getline(context, 0, args)) != context.nil) {
485472
ary.append(context, line);
486473
}
487474
return ary;
@@ -586,9 +573,9 @@ public static IRubyObject codepoints(ThreadContext context, IRubyObject recv, Bl
586573
public static IRubyObject each_line(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
587574
if (!block.isGiven()) return enumeratorize(context.runtime, recv, "each_line", args);
588575

576+
final int callInfo = ThreadContext.resetCallInfo(context);
589577
Arity.checkArgumentCount(context, args, 0, 1);
590578

591-
int callInfo = context.callInfo;
592579
ArgsFileData data = ArgsFileData.getArgsFileData(context.runtime);
593580

594581
if (!data.next_argv(context)) return context.nil;
@@ -601,7 +588,7 @@ public static IRubyObject each_line(ThreadContext context, IRubyObject recv, IRu
601588
}
602589

603590
IRubyObject str;
604-
while ((str = argfGetlineLoopWithKeywords(context, recv, args, callInfo)) != context.nil) {
591+
while ((str = argf_getline(context, callInfo, args)) != context.nil) {
605592
block.yield(context, str);
606593
}
607594

core/src/main/java/org/jruby/RubyData.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@
4040
import static org.jruby.runtime.Arity.checkArgumentCount;
4141
import static org.jruby.runtime.Helpers.invokedynamic;
4242
import static org.jruby.runtime.ThreadContext.CALL_KEYWORD;
43-
import static org.jruby.runtime.ThreadContext.CALL_KEYWORD_EMPTY;
44-
import static org.jruby.runtime.ThreadContext.clearCallInfo;
45-
import static org.jruby.runtime.ThreadContext.hasKeywords;
4643
import static org.jruby.runtime.ThreadContext.hasNonemptyKeywords;
47-
import static org.jruby.runtime.ThreadContext.resetCallInfo;
4844
import static org.jruby.runtime.invokedynamic.MethodNames.HASH;
4945
import static org.jruby.util.RubyStringBuilder.str;
5046

@@ -88,14 +84,14 @@ public static RubyClass define(ThreadContext context, IRubyObject self, IRubyObj
8884

8985
@JRubyMethod(keywords = true, rest = true)
9086
public static void initialize(ThreadContext context, IRubyObject self, IRubyObject[] args) {
87+
ThreadContext.resetCallInfo(context); // we don't directly use callInfo here
88+
9189
RubyBasicObject selfObj = (RubyBasicObject) self;
90+
9291
selfObj.checkFrozen();
9392
RubyArray<RubySymbol> members = getStructMembers(self);
9493
int numMembers = members.size();
9594

96-
// we don't directly use callInfo here
97-
ThreadContext.clearCallInfo(context);
98-
9995
if (args.length == 0) {
10096
if (numMembers > 0) {
10197
throw keywordError(context, "missing", members);
@@ -245,7 +241,7 @@ public static RubyHash deconstruct_keys(ThreadContext context, IRubyObject self,
245241
@JRubyMethod(keywords = true, optional = 1, checkArity = false)
246242
public static IRubyObject with(ThreadContext context, IRubyObject self, IRubyObject[] args) {
247243
IRubyObject kwargs = IRRuntimeHelpers.receiveKeywords(context, args, false, true, false);
248-
if (kwargs == UndefinedValue.UNDEFINED || kwargs.isNil()) {
244+
if (!(kwargs instanceof RubyHash)) {
249245
checkArgumentCount(context, args.length, 0, 0);
250246
return self;
251247
}
@@ -255,7 +251,7 @@ public static IRubyObject with(ThreadContext context, IRubyObject self, IRubyObj
255251
RubyHash kwargsHash = (RubyHash) kwargs;
256252
RubyHash h = to_h(context, self, Block.NULL_BLOCK);
257253
h.addAll(context, kwargsHash);
258-
setCallInfo(context, CALL_KEYWORD);
254+
context.callInfo = CALL_KEYWORD;
259255
return DataMethods.rbNew(context, self.getMetaClass(), h);
260256
}
261257

@@ -283,7 +279,7 @@ public static IRubyObject rbNew(ThreadContext context, IRubyObject self, IRubyOb
283279

284280
IRubyObject dataObject = klass.getAllocator().allocate(context.runtime, klass);
285281

286-
setCallInfo(context, ThreadContext.CALL_KEYWORD);
282+
context.callInfo = ThreadContext.CALL_KEYWORD;
287283

288284
// TODO: avoid initialize and hash overhead for known types
289285
dataObject.getMetaClass().getBaseCallSite(RubyClass.CS_IDX_INITIALIZE)
@@ -295,10 +291,9 @@ public static IRubyObject rbNew(ThreadContext context, IRubyObject self, IRubyOb
295291

296292
@JRubyMethod(name = {"new", "[]"}, keywords = true)
297293
public static IRubyObject rbNew(ThreadContext context, IRubyObject self) {
298-
RubyClass klass = (RubyClass) self;
299-
300-
clearCallInfo(context);
294+
ThreadContext.resetCallInfo(context);
301295

296+
RubyClass klass = (RubyClass) self;
302297
IRubyObject dataObject = klass.getAllocator().allocate(context.runtime, klass);
303298

304299
dataObject.getMetaClass().getBaseCallSite(RubyClass.CS_IDX_INITIALIZE)
@@ -309,10 +304,10 @@ public static IRubyObject rbNew(ThreadContext context, IRubyObject self) {
309304

310305
@JRubyMethod(name = {"new", "[]"}, keywords = true)
311306
public static IRubyObject rbNew(ThreadContext context, IRubyObject self, IRubyObject hashOrElt) {
312-
RubyClass klass = (RubyClass) self;
307+
int callInfo = ThreadContext.resetCallInfo(context);
313308

309+
RubyClass klass = (RubyClass) self;
314310
RubyHash init;
315-
int callInfo = resetCallInfo(context);
316311
if (hasNonemptyKeywords(callInfo)) {
317312
if (!(hashOrElt instanceof RubyHash)) {
318313
throw argumentError(context, 1, 0, 0);
@@ -333,7 +328,7 @@ public static IRubyObject rbNew(ThreadContext context, IRubyObject self, IRubyOb
333328

334329
IRubyObject dataObject = klass.getAllocator().allocate(context.runtime, klass);
335330

336-
setCallInfo(context, callInfo);
331+
context.callInfo = callInfo;
337332

338333
// TODO: avoid initialize and hash overhead for known types
339334
dataObject.getMetaClass().getBaseCallSite(RubyClass.CS_IDX_INITIALIZE)

core/src/main/java/org/jruby/RubyDir.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ private static class GlobOptions {
234234
private static void globOptions(ThreadContext context, IRubyObject[] args, String[] keys, GlobOptions options) {
235235
Ruby runtime = context.runtime;
236236

237-
// just clear callInfo for now; future PR will handle it appropriately
238-
ThreadContext.resetCallInfo(context);
239-
240237
if (args.length > 1) {
241238
IRubyObject tmp = TypeConverter.checkHashType(runtime, args[args.length - 1]);
242239
boolean processFlags = keys == BASE_FLAGS_KEYWORDS;
@@ -277,6 +274,7 @@ private static void globOptions(ThreadContext context, IRubyObject[] args, Strin
277274

278275
@JRubyMethod(name = "[]", rest = true, meta = true, keywords = true)
279276
public static IRubyObject aref(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
277+
ThreadContext.resetCallInfo(context);
280278
Ruby runtime = context.runtime;
281279
GlobOptions options = new GlobOptions();
282280
globOptions(context, args, BASE_KEYWORDS, options);
@@ -324,8 +322,9 @@ private static ByteList globArgumentAsByteList(ThreadContext context, IRubyObjec
324322
* with each filename is passed to the block in turn. In this case, Nil is
325323
* returned.
326324
*/
327-
@JRubyMethod(required = 1, optional = 2, checkArity = false, meta = true)
325+
@JRubyMethod(required = 1, optional = 2, checkArity = false, meta = true, keywords = true)
328326
public static IRubyObject glob(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
327+
ThreadContext.resetCallInfo(context);
329328
Arity.checkArgumentCount(context, args, 1, 3);
330329

331330
Ruby runtime = context.runtime;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static org.jruby.runtime.ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR;
5555
import static org.jruby.runtime.ThreadContext.CALL_KEYWORD;
5656
import static org.jruby.runtime.ThreadContext.hasKeywords;
57+
import static org.jruby.runtime.ThreadContext.hasNonemptyKeywords;
5758
import static org.jruby.runtime.ThreadContext.resetCallInfo;
5859
import static org.jruby.runtime.Visibility.PRIVATE;
5960

@@ -212,10 +213,9 @@ public static IRubyObject enumeratorize(Ruby runtime, RubyClass type, IRubyObjec
212213
// and used internally to create enum from Enumerator::Lazy#eager
213214
@JRubyMethod(name = "__from", meta = true, required = 2, optional = 2, checkArity = false, visibility = PRIVATE, keywords = true)
214215
public static IRubyObject __from(ThreadContext context, IRubyObject klass, IRubyObject[] args) {
215-
int argc = Arity.checkArgumentCount(context, args, 2, 4);
216+
boolean keywords = hasNonemptyKeywords(ThreadContext.resetCallInfo(context));
216217

217-
boolean keywords = (context.callInfo & CALL_KEYWORD) != 0 && (context.callInfo & ThreadContext.CALL_KEYWORD_EMPTY) == 0;
218-
ThreadContext.resetCallInfo(context);
218+
int argc = Arity.checkArgumentCount(context, args, 2, 4);
219219

220220
// Lazy.__from(enum, method, *args, size)
221221
IRubyObject object = args[0];

core/src/main/java/org/jruby/RubyFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public IRubyObject flock(ThreadContext context, IRubyObject operation) {
297297
@JRubyMethod(name = "initialize", required = 1, optional = 3, checkArity = false, visibility = PRIVATE, keywords = true)
298298
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
299299
// capture callInfo for delegating to IO#initialize
300-
int callInfo = context.callInfo;
300+
final int callInfo = context.callInfo;
301301
IRubyObject keywords = IRRuntimeHelpers.receiveKeywords(context, args, false, true, false);
302302
// Mild hack. We want to arity-mismatch if extra arg is not really a kwarg but not if it is one.
303303
int maxArgs = keywords instanceof RubyHash ? 4 : 3;
@@ -309,7 +309,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block b
309309
IRubyObject fd = TypeConverter.convertToTypeWithCheck(context, args[0], context.runtime.getFixnum(), sites(context).to_int_checked);
310310
if (!fd.isNil()) {
311311
// restore callInfo for delegated call to IO#initialize
312-
IRRuntimeHelpers.setCallInfo(context, callInfo);
312+
context.callInfo = callInfo;
313313
return switch (argc) {
314314
case 1 -> super.initialize(context, fd, block);
315315
case 2 -> super.initialize(context, fd, args[1], block);

core/src/main/java/org/jruby/RubyHash.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import static org.jruby.api.Convert.asBoolean;
6464
import static org.jruby.api.Define.defineClass;
6565
import static org.jruby.api.Error.*;
66+
import static org.jruby.runtime.ThreadContext.hasKeywords;
6667
import static org.jruby.runtime.Visibility.PRIVATE;
6768

6869
// Design overview:
@@ -455,7 +456,7 @@ public IRubyObject initialize(ThreadContext context, final Block block) {
455456
return getDelegate().initialize(context, block);
456457
}
457458

458-
@JRubyMethod(visibility = PRIVATE)
459+
@JRubyMethod(visibility = PRIVATE, keywords = true)
459460
public IRubyObject initialize(ThreadContext context, IRubyObject _default, final Block block) {
460461
return getDelegate().initialize(context, _default, block);
461462
}

core/src/main/java/org/jruby/RubyHashLinkedBuckets.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,11 @@ public IRubyObject initialize(ThreadContext context, final Block block) {
638638

639639
@JRubyMethod(visibility = PRIVATE)
640640
public IRubyObject initialize(ThreadContext context, IRubyObject _default, final Block block) {
641-
boolean keywords = hasKeywords(resetCallInfo(context));
641+
boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context));
642642
modify();
643643

644644
if (keywords) {
645-
IRubyObject[] opts = ArgsUtil.extractKeywordArgs(context, (RubyHashLinkedBuckets) _default, "capacity");
645+
IRubyObject[] opts = ArgsUtil.extractKeywordArgs(context, (RubyHash) _default, "capacity");
646646
// This will allocFirst twice since it already happened before initialize was called. I think this is ok?
647647
if (opts[0] instanceof RubyFixnum fixnum && fixnum.asInt(context) > 0) allocFirst(fixnum.asInt(context));
648648

@@ -663,9 +663,9 @@ public IRubyObject initialize(ThreadContext context, IRubyObject _default, final
663663

664664
@JRubyMethod(visibility = PRIVATE, keywords = true)
665665
public IRubyObject initialize(ThreadContext context, IRubyObject _default, IRubyObject hash, final Block block) {
666-
if (!hasKeywords(resetCallInfo(context))) throw argumentError(context, 2, 0, 1);
666+
if (!hasKeywords(ThreadContext.resetCallInfo(context))) throw argumentError(context, 2, 0, 1);
667667

668-
IRubyObject[] opts = ArgsUtil.extractKeywordArgs(context, (RubyHashLinkedBuckets) hash, "capacity");
668+
IRubyObject[] opts = ArgsUtil.extractKeywordArgs(context, (RubyHash) hash, "capacity");
669669

670670
// This will allocFirst twice since it already happened before initialize was called. I think this is ok?
671671
if (opts[0] instanceof RubyFixnum fixnum && fixnum.asInt(context) > 0) allocFirst(fixnum.asInt(context));

0 commit comments

Comments
 (0)