7878import static org .jruby .api .Define .defineClass ;
7979import static org .jruby .api .Error .argumentError ;
8080import 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 ;
8382import static org .jruby .runtime .Visibility .PRIVATE ;
8483
8584public 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
0 commit comments