summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog8
-rw-r--r--io.c20
-rw-r--r--test/ruby/test_argf.rb8
3 files changed, 32 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 6a2a5f3c607..52e823bb259 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/io.c b/io.c
index 31bdf7e0a3a..2656b2bae8c 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;
+ }
}
}
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index a1f260147ea..ffd5096789e 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'