1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-10-29 16:40:05 +00:00
parent 2e51b7f9da
commit 86ade65104
3 changed files with 34 additions and 9 deletions

View file

@ -17,6 +17,16 @@ Wed Oct 29 23:57:29 2008 Yusuke Endoh <mame@tsg.ne.jp>
* array.c (rb_ary_sort_bang): replacing array during sort broke
invariant of array.
Wed Oct 29 21:06:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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@tsg.ne.jp>
* test/webrick/utils.rb (start_server): provide a reference to log of

9
io.c
View file

@ -1057,6 +1057,8 @@ rb_io_set_pos(VALUE io, VALUE offset)
return OFFT2NUM(pos);
}
static void clear_readconv(rb_io_t *fptr);
/*
* call-seq:
* ios.rewind => 0
@ -1082,6 +1084,9 @@ rb_io_rewind(VALUE io)
ARGF.gets_lineno -= fptr->lineno;
}
fptr->lineno = 0;
if (fptr->readconv) {
clear_readconv(fptr);
}
return INT2FIX(0);
}
@ -1499,8 +1504,10 @@ more_char(rb_io_t *fptr)
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) {

View file

@ -42,8 +42,9 @@ class TestFile < Test::Unit::TestCase
f.print "abc"
f.truncate(0)
f.print "def"
f.close
f.flush
assert_equal("\0\0\0def", File.read(f.path), "[ruby-dev:24191]")
f.close
end
def test_truncate_rbuf
@ -68,7 +69,8 @@ class TestFile < Test::Unit::TestCase
[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 @@ class TestFile < Test::Unit::TestCase
[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 @@ class TestFile < Test::Unit::TestCase
[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 @@ class TestFile < Test::Unit::TestCase
[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 @@ class TestFile < Test::Unit::TestCase
[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 @@ class TestFile < Test::Unit::TestCase
[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 @@ class TestFile < Test::Unit::TestCase
[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