ruby-changes:45052
From: nobu <ko1@a...>
Date: Tue, 20 Dec 2016 17:25:11 +0900 (JST)
Subject: [ruby-changes:45052] nobu:r57125 (trunk): io.c: update argf lineno
nobu 2016-12-20 17:25:03 +0900 (Tue, 20 Dec 2016) New Revision: 57125 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57125 Log: io.c: update argf lineno * io.c (argf_rewind): rewind line number in non-global ARGF instance. Modified files: trunk/io.c trunk/test/ruby/test_argf.rb Index: io.c =================================================================== --- io.c (revision 57124) +++ io.c (revision 57125) @@ -11098,11 +11098,19 @@ argf_set_pos(VALUE argf, VALUE offset) https://github.com/ruby/ruby/blob/trunk/io.c#L11098 static VALUE argf_rewind(VALUE argf) { + VALUE ret; + int old_lineno; + if (!next_argv()) { rb_raise(rb_eArgError, "no stream to rewind"); } ARGF_FORWARD(0, 0); - return rb_io_rewind(ARGF.current_file); + old_lineno = RFILE(ARGF.current_file)->fptr->lineno; + ret = rb_io_rewind(ARGF.current_file); + if (!global_argf_p(argf)) { + ARGF.last_lineno = ARGF.lineno -= old_lineno; + } + return ret; } /* Index: test/ruby/test_argf.rb =================================================================== --- test/ruby/test_argf.rb (revision 57124) +++ test/ruby/test_argf.rb (revision 57125) @@ -78,15 +78,15 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L78 p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["2", 2, "2", 2] a.rewind b.rewind - p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["1", 1, "1", 3] - p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["2", 2, "2", 4] - p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["3", 3, "3", 5] - p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["4", 4, "4", 6] - p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 7] + p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["1", 1, "1", 1] + p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["2", 2, "2", 2] + p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["3", 3, "3", 3] + p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["4", 4, "4", 4] + p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 5] a.rewind b.rewind - p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 8] - p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["6", 6, "6", 9] + p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 5] + p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["6", 6, "6", 6] SRC end @@ -144,6 +144,9 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L144 assert_equal(3, f.lineno) assert_equal((1..3).map {|i| [i, "#{i}\n"]}, result) + f.rewind + assert_equal(2, f.lineno) + f = ARGF.class.new(@t1.path, @t2.path, @t3.path) f.each_char.to_a assert_equal(0, f.lineno) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/