ruby-changes:8525
From: yugui <ko1@a...>
Date: Thu, 30 Oct 2008 21:11:01 +0900 (JST)
Subject: [ruby-changes:8525] Ruby:r20058 (ruby_1_9_1): merges r20045 from trunk into ruby_1_9_1.
yugui 2008-10-30 21:09:24 +0900 (Thu, 30 Oct 2008) New Revision: 20058 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20058 Log: merges r20045 from trunk into ruby_1_9_1. * io.c (rb_io_rewind): should reset fptr->readconv if it's available. * io.c (more_char): clear readconv at EOF. * test/ruby/test_file.rb: should not read after EOF. use rewind instead. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/io.c branches/ruby_1_9_1/test/ruby/test_file.rb Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20057) +++ ruby_1_9_1/ChangeLog (revision 20058) @@ -28,6 +28,16 @@ * array.c (rb_ary_sort_bang): replacing array during sort broke invariant of array. [ruby-dev:36983] +Wed Oct 29 21:06:46 2008 Yukihiro Matsumoto <matz@r...> + + * io.c (rb_io_rewind): should reset fptr->readconv if it's + available. + + * io.c (more_char): clear readconv at EOF. + + * test/ruby/test_file.rb: should not read after EOF. use rewind + instead. + Wed Oct 29 20:45:08 2008 Yusuke Endoh <mame@t...> * test/webrick/utils.rb (start_server): provide a reference to log of Index: ruby_1_9_1/io.c =================================================================== --- ruby_1_9_1/io.c (revision 20057) +++ ruby_1_9_1/io.c (revision 20058) @@ -1057,6 +1057,8 @@ return OFFT2NUM(pos); } +static void clear_readconv(rb_io_t *fptr); + /* * call-seq: * ios.rewind => 0 @@ -1082,6 +1084,9 @@ ARGF.gets_lineno -= fptr->lineno; } fptr->lineno = 0; + if (fptr->readconv) { + clear_readconv(fptr); + } return INT2FIX(0); } @@ -1499,8 +1504,10 @@ if (cbuf_len0 != fptr->cbuf_len) return 0; - if (res == econv_finished) + if (res == econv_finished) { + clear_readconv(fptr); return -1; + } if (res == econv_source_buffer_empty) { if (fptr->rbuf_len == 0) { Index: ruby_1_9_1/test/ruby/test_file.rb =================================================================== --- ruby_1_9_1/test/ruby/test_file.rb (revision 20057) +++ ruby_1_9_1/test/ruby/test_file.rb (revision 20058) @@ -42,8 +42,9 @@ f.print "abc" f.truncate(0) f.print "def" + f.flush + assert_equal("\0\0\0def", File.read(f.path), "[ruby-dev:24191]") f.close - assert_equal("\0\0\0def", File.read(f.path), "[ruby-dev:24191]") end def test_truncate_rbuf @@ -68,7 +69,8 @@ [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind assert_equal("a", f.read, "mode = <#{mode}>") end end @@ -77,7 +79,8 @@ [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind assert_equal("a", f.gets("a"), "mode = <#{mode}>") end end @@ -86,7 +89,8 @@ [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "wb") {|g| g.print "\na" } + f.print "\na" + f.rewind assert_equal("a", f.gets(""), "mode = <#{mode}>") end end @@ -95,7 +99,8 @@ [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind result = [] f.each_char {|b| result << b } assert_equal([?a], result, "mode = <#{mode}>") @@ -106,7 +111,8 @@ [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind result = [] f.each_byte {|b| result << b.chr } assert_equal([?a], result, "mode = <#{mode}>") @@ -117,7 +123,8 @@ [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind assert_equal(?a, f.getc, "mode = <#{mode}>") end end @@ -126,7 +133,8 @@ [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| f = Tempfile.new("test-extended-file", mode) assert_nil(f.getc) - open(f.path, "w") {|g| g.print "a" } + f.print "a" + f.rewind assert_equal(?a, f.getbyte.chr, "mode = <#{mode}>") end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/