diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | io.c | 20 | ||||
-rw-r--r-- | test/ruby/test_argf.rb | 8 |
3 files changed, 32 insertions, 4 deletions
@@ -1,3 +1,11 @@ +Mon Apr 12 00:51:21 2010 Kazuhiro NISHIYAMA <zn@mbf.nifty.com> + + * io.c (rb_io_getline_fast, rb_io_getline_1): fix ARGF.lineno + behavior. [ruby-core:25205] + + * test/ruby/test_argf.rb (TestArgf#test_lineno3): add a test for + above. + Sun Apr 11 23:25:17 2010 Yutaka Kanemoto <kanemoto@ruby-lang.org> * configure.in: can not load libraries if --with-opt-dir is used @@ -2286,7 +2286,7 @@ swallow(rb_io_t *fptr, int term) } static VALUE -rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc) +rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, VALUE io) { VALUE str = Qnil; int len = 0; @@ -2328,7 +2328,13 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc) str = io_enc_str(str, fptr); ENC_CODERANGE_SET(str, cr); fptr->lineno++; - ARGF.last_lineno = fptr->lineno; + if (io == ARGF.current_file) { + ARGF.lineno++; + ARGF.last_lineno = ARGF.lineno; + } + else { + ARGF.last_lineno = fptr->lineno; + } return str; } @@ -2397,7 +2403,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io) } else if (rs == rb_default_rs && limit < 0 && !NEED_READCONV(fptr) && rb_enc_asciicompat(enc = io_read_encoding(fptr))) { - return rb_io_getline_fast(fptr, enc); + return rb_io_getline_fast(fptr, enc, io); } else { int c, newline = -1; @@ -2466,7 +2472,13 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io) if (!NIL_P(str)) { if (!nolimit) { fptr->lineno++; - ARGF.last_lineno = fptr->lineno; + if (io == ARGF.current_file) { + ARGF.lineno++; + ARGF.last_lineno = ARGF.lineno; + } + else { + ARGF.last_lineno = fptr->lineno; + } } } diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index a1f260147e..ffd5096789 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -127,6 +127,14 @@ class TestArgf < Test::Unit::TestCase SRC end + def test_lineno3 + assert_in_out_err(["-", @t1.path, @t2.path], <<-INPUT, %w"1 1 1 2 2 2 3 3 1 4 4 2", [], "[ruby-core:25205]") + ARGF.each do |line| + puts [$., ARGF.lineno, ARGF.file.lineno] + end + INPUT + end + def test_inplace assert_in_out_err(["-", @t1.path, @t2.path, @t3.path], <<-INPUT, [], []) ARGF.inplace_mode = '.bak' |