summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-11 15:56:43 +0000
committerkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-11 15:56:43 +0000
commit0a6d09330c9b8b179be1174137e79e4075819275 (patch)
tree58956b2af970bfa3eaea222b046f8d014540ab0c /io.c
parent78a59b37a161080473ace8d2d14f1fbf6466d025 (diff)
* 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
Diffstat (limited to 'io.c')
-rw-r--r--io.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/io.c b/io.c
index 31bdf7e0a3..2656b2bae8 100644
--- a/io.c
+++ b/io.c
@@ -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;
+ }
}
}