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

* ext/stringio/stringio.c (strio_read): do not set EOF flag when

requested length is zero.  [ruby-dev:22214]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-12-10 08:54:56 +00:00
parent f449c04a36
commit ba18b0c6cb
3 changed files with 14 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Wed Dec 10 17:54:51 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_read): do not set EOF flag when
requested length is zero. [ruby-dev:22214]
Wed Dec 10 17:17:18 2003 Yukihiro Matsumoto <matz@ruby-lang.org> Wed Dec 10 17:17:18 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (read_all): should return given string even if data read is * io.c (read_all): should return given string even if data read is
@ -11,8 +16,8 @@ Wed Dec 10 17:16:06 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/ruby/ut_eof.rb (TestEOF::Seek): test behaviors at reading * test/ruby/ut_eof.rb (TestEOF::Seek): test behaviors at reading
beyond EOF. beyond EOF.
* test/ruby/test_file.rb, * test/stringio/test_stringio.rb: * test/ruby/test_file.rb, test/stringio/test_stringio.rb: include
include TestEOF::Seek test case. TestEOF::Seek test case.
Wed Dec 10 15:01:19 2003 Shugo Maeda <shugo@ruby-lang.org> Wed Dec 10 15:01:19 2003 Shugo Maeda <shugo@ruby-lang.org>

View file

@ -836,12 +836,12 @@ strio_read(argc, argv, self)
{ {
struct StringIO *ptr = readable(StringIO(self)); struct StringIO *ptr = readable(StringIO(self));
VALUE str; VALUE str;
long len; long len, olen;
switch (argc) { switch (argc) {
case 1: case 1:
if (!NIL_P(argv[0])) { if (!NIL_P(argv[0])) {
len = NUM2LONG(argv[0]); len = olen = NUM2LONG(argv[0]);
if (len < 0) { if (len < 0) {
rb_raise(rb_eArgError, "negative length %ld given", len); rb_raise(rb_eArgError, "negative length %ld given", len);
} }
@ -856,6 +856,7 @@ strio_read(argc, argv, self)
} }
/* fall through */ /* fall through */
case 0: case 0:
olen = -1;
len = RSTRING(ptr->string)->len - ptr->pos; len = RSTRING(ptr->string)->len - ptr->pos;
if (len == 0 && ptr->pos == RSTRING(ptr->string)->len) { if (len == 0 && ptr->pos == RSTRING(ptr->string)->len) {
if (ptr->flags & STRIO_EOF) return Qnil; if (ptr->flags & STRIO_EOF) return Qnil;
@ -868,7 +869,7 @@ strio_read(argc, argv, self)
str = rb_str_substr(ptr->string, ptr->pos, len); str = rb_str_substr(ptr->string, ptr->pos, len);
if (NIL_P(str)) { if (NIL_P(str)) {
if (!(ptr->flags & STRIO_EOF)) str = rb_str_new(0, 0); if (!(ptr->flags & STRIO_EOF)) str = rb_str_new(0, 0);
ptr->flags |= STRIO_EOF; if (olen) ptr->flags |= STRIO_EOF;
} }
else { else {
ptr->pos += RSTRING(str)->len; ptr->pos += RSTRING(str)->len;

View file

@ -64,7 +64,10 @@ module TestEOF
def test_eof_0_seek def test_eof_0_seek
open_file_seek("", 10) {|f| open_file_seek("", 10) {|f|
assert_equal(10, f.pos)
assert_equal("", f.read(0))
assert_equal("", f.read) assert_equal("", f.read)
assert_equal(nil, f.read(0))
assert_equal(nil, f.read) assert_equal(nil, f.read)
} }
end end