diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-24 05:23:32 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-24 05:23:32 +0000 |
commit | 6fe8d987ce2296174dcd3e4f3c382f8114728210 (patch) | |
tree | 2ec4e1c67c58d3f4851b3bb15902034afcbfb8e5 | |
parent | 73d77c8f572b760b4c868579188fc39f360151cb (diff) |
* ext/stringio/stringio.c (strio_read): clear the buffer argument
when returning nil. [ruby-dev:22363]
* test/ruby/ut_eof.rb (TestEOF::test_eof_0, TestEOF::test_eof_1):
add buffer argument tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ext/stringio/stringio.c | 2 | ||||
-rw-r--r-- | test/ruby/ut_eof.rb | 20 |
3 files changed, 30 insertions, 0 deletions
@@ -1,3 +1,11 @@ +Wed Dec 24 14:23:27 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * ext/stringio/stringio.c (strio_read): clear the buffer argument + when returning nil. [ruby-dev:22363] + + * test/ruby/ut_eof.rb (TestEOF::test_eof_0, TestEOF::test_eof_1): + add buffer argument tests. + Wed Dec 24 14:07:55 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/test/unit/assertions.rb: Modules are allowed to rescue. diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 1bab5b4d1f..8d3275b2b8 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -851,9 +851,11 @@ strio_read(argc, argv, self) } if (len > 0 && ptr->pos >= RSTRING(ptr->string)->len) { ptr->flags |= STRIO_EOF; + if (!NIL_P(str)) rb_str_resize(str, 0); return Qnil; } else if (ptr->flags & STRIO_EOF) { + if (!NIL_P(str)) rb_str_resize(str, 0); return Qnil; } break; diff --git a/test/ruby/ut_eof.rb b/test/ruby/ut_eof.rb index 8b3cc8101b..eff0bddc0b 100644 --- a/test/ruby/ut_eof.rb +++ b/test/ruby/ut_eof.rb @@ -14,6 +14,16 @@ module TestEOF assert_equal("", f.read) assert_nil(f.read(1)) } + open_file("") {|f| + s = "x" + assert_equal("", f.read(nil, s)) + assert_equal("", s) + } + open_file("") {|f| + s = "x" + assert_nil(f.read(10, s)) + assert_equal("", s) + } end def test_eof_0_rw @@ -61,6 +71,16 @@ module TestEOF assert_equal("a", f.read) assert_nil(f.read(0)) } + open_file("a") {|f| + s = "x" + assert_equal("a", f.read(nil, s)) + assert_equal("a", s) + } + open_file("a") {|f| + s = "x" + assert_equal("a", f.read(10, s)) + assert_equal("a", s) + } end module Seek |