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): never return nil at

unlimited read.  [ruby-dev:22334]

* ext/stringio/stringio.c (strio_read): support second
  argument.  [ruby-dev:22350]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-12-24 01:29:57 +00:00
parent 8365bb013f
commit c2b63d249f
2 changed files with 30 additions and 4 deletions

View file

@ -1,3 +1,11 @@
Wed Dec 24 10:29:53 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_read): never return nil at
unlimited read. [ruby-dev:22334]
* ext/stringio/stringio.c (strio_read): support second
argument. [ruby-dev:22350]
Wed Dec 24 09:38:49 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (arg): should return 0 after error. [ruby-dev:22360]

View file

@ -835,10 +835,14 @@ strio_read(argc, argv, self)
VALUE self;
{
struct StringIO *ptr = readable(StringIO(self));
VALUE str;
VALUE str = Qnil;
long len, olen;
switch (argc) {
case 2:
str = argv[1];
StringValue(str);
rb_str_modify(str);
case 1:
if (!NIL_P(argv[0])) {
len = olen = NUM2LONG(argv[0]);
@ -859,8 +863,14 @@ strio_read(argc, argv, self)
olen = -1;
len = RSTRING(ptr->string)->len;
if (len <= ptr->pos) {
if (ptr->flags & STRIO_EOF) return Qnil;
len = 0;
ptr->flags |= STRIO_EOF;
if (NIL_P(str)) {
str = rb_str_new(0, 0);
}
else {
rb_str_resize(str, 0);
}
return str;
}
else {
len -= ptr->pos;
@ -869,7 +879,15 @@ strio_read(argc, argv, self)
default:
rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
}
str = rb_str_substr(ptr->string, ptr->pos, len);
if (NIL_P(str)) {
str = rb_str_substr(ptr->string, ptr->pos, len);
}
else {
long rest = RSTRING(ptr->string)->len - ptr->pos;
if (len > rest) len = rest;
rb_str_resize(str, len);
MEMCPY(RSTRING(str)->ptr, RSTRING(ptr->string)->ptr, char, len);
}
if (NIL_P(str)) {
if (!(ptr->flags & STRIO_EOF)) str = rb_str_new(0, 0);
len = 0;