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

ruby-changes:27945

From: nobu <ko1@a...>
Date: Fri, 29 Mar 2013 16:51:53 +0900 (JST)
Subject: [ruby-changes:27945] nobu:r39997 (trunk): io.c: get rid of IOError when skipped while iteration

nobu	2013-03-29 16:51:43 +0900 (Fri, 29 Mar 2013)

  New Revision: 39997

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

  Log:
    io.c: get rid of IOError when skipped while iteration
    
    * io.c (argf_next_argv): set init flag if succeeded to forward, after
      skipping.
    * io.c (argf_block_call_i, argf_block_call): no more forwarding if
      forwarded after skipping.  [ruby-list:49185]

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39996)
+++ ChangeLog	(revision 39997)
@@ -1,4 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Fri Mar 29 16:51:04 2013  Nobuyoshi Nakada  <nobu@r...>
+Fri Mar 29 16:51:39 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (argf_next_argv): set init flag if succeeded to forward, after
+	  skipping.
+
+	* io.c (argf_block_call_i, argf_block_call): no more forwarding if
+	  forwarded after skipping.  [ruby-list:49185]
 
 	* io.c (argf_close): deal with init flag.
 
Index: io.c
===================================================================
--- io.c	(revision 39996)
+++ io.c	(revision 39997)
@@ -7614,7 +7614,6 @@ argf_next_argv(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L7614
 	else if (ARGF.next_p == -1 && RARRAY_LEN(ARGF.argv) > 0) {
 	    ARGF.next_p = 1;
 	}
-	ARGF.init_p = 1;
     }
 
     if (ARGF.next_p == 1) {
@@ -7747,6 +7746,7 @@ argf_next_argv(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L7746
 	    rb_stdout = orig_stdout;
 	}
     }
+    if (ARGF.init_p == -1) ARGF.init_p = 1;
     return TRUE;
 }
 
@@ -10927,7 +10927,7 @@ argf_readbyte(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L10927
     return c;
 }
 
-#define FOREACH_ARGF() for (; next_argv(); ARGF.next_p = 1)
+#define FOREACH_ARGF() while (next_argv())
 
 static VALUE
 argf_block_call_i(VALUE i, VALUE argf, int argc, VALUE *argv)
@@ -10935,7 +10935,7 @@ argf_block_call_i(VALUE i, VALUE argf, i https://github.com/ruby/ruby/blob/trunk/io.c#L10935
     const VALUE current = ARGF.current_file;
     rb_yield_values2(argc, argv);
     if (ARGF.init_p == -1 || current != ARGF.current_file) {
-	rb_iter_break();
+	rb_iter_break_value(Qundef);
     }
     return Qnil;
 }
@@ -10943,7 +10943,8 @@ argf_block_call_i(VALUE i, VALUE argf, i https://github.com/ruby/ruby/blob/trunk/io.c#L10943
 static void
 argf_block_call(ID mid, int argc, VALUE *argv, VALUE argf)
 {
-    rb_block_call(ARGF.current_file, mid, argc, argv, argf_block_call_i, argf);
+    VALUE ret = rb_block_call(ARGF.current_file, mid, argc, argv, argf_block_call_i, argf);
+    if (ret != Qundef) ARGF.next_p = 1;
 }
 
 /*
Index: test/ruby/test_argf.rb
===================================================================
--- test/ruby/test_argf.rb	(revision 39996)
+++ test/ruby/test_argf.rb	(revision 39997)
@@ -689,6 +689,11 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L689
     SRC
       assert_equal("1\n3\n5\n", f.read, '[ruby-list:49185]')
     end
+    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+      ARGF.each_line {|l| ARGF.skip; puts [l, ARGF.gets].map {|s| s ? s.chomp : s.inspect}.join("+")}
+    SRC
+      assert_equal("1+3\n4+5\n6+nil\n", f.read, '[ruby-list:49185]')
+    end
   end
 
   def test_skip_in_each_byte

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

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