[前][次][番号順一覧][スレッド一覧]

ruby-changes:15413

From: kazu <ko1@a...>
Date: Mon, 12 Apr 2010 00:57:03 +0900 (JST)
Subject: [ruby-changes:15413] Ruby:r27308 (trunk): * io.c (rb_io_getline_fast, rb_io_getline_1): fix ARGF.lineno behavior.

kazu	2010-04-12 00:56:43 +0900 (Mon, 12 Apr 2010)

  New Revision: 27308

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27308

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

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_argf.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27307)
+++ ChangeLog	(revision 27308)
@@ -1,3 +1,11 @@
+Mon Apr 12 00:51:21 2010  Kazuhiro NISHIYAMA  <zn@m...>
+
+	* 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@r...>
 
 	* configure.in: can not load libraries if --with-opt-dir is used
Index: io.c
===================================================================
--- io.c	(revision 27307)
+++ io.c	(revision 27308)
@@ -2286,7 +2286,7 @@
 }
 
 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 @@
     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 @@
     }
     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 @@
     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;
+	    }
 	}
     }
 
Index: test/ruby/test_argf.rb
===================================================================
--- test/ruby/test_argf.rb	(revision 27307)
+++ test/ruby/test_argf.rb	(revision 27308)
@@ -127,6 +127,14 @@
     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'

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]