1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kazu 2010-04-11 15:56:43 +00:00
parent 78a59b37a1
commit 0a6d09330c
3 changed files with 32 additions and 4 deletions

View file

@ -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

20
io.c
View file

@ -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;
}
}
}

View file

@ -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'