зеркало из https://github.com/github/ruby.git
* 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:
Родитель
8365bb013f
Коммит
c2b63d249f
|
@ -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>
|
Wed Dec 24 09:38:49 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* parse.y (arg): should return 0 after error. [ruby-dev:22360]
|
* parse.y (arg): should return 0 after error. [ruby-dev:22360]
|
||||||
|
|
|
@ -835,10 +835,14 @@ strio_read(argc, argv, self)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
{
|
{
|
||||||
struct StringIO *ptr = readable(StringIO(self));
|
struct StringIO *ptr = readable(StringIO(self));
|
||||||
VALUE str;
|
VALUE str = Qnil;
|
||||||
long len, olen;
|
long len, olen;
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
|
case 2:
|
||||||
|
str = argv[1];
|
||||||
|
StringValue(str);
|
||||||
|
rb_str_modify(str);
|
||||||
case 1:
|
case 1:
|
||||||
if (!NIL_P(argv[0])) {
|
if (!NIL_P(argv[0])) {
|
||||||
len = olen = NUM2LONG(argv[0]);
|
len = olen = NUM2LONG(argv[0]);
|
||||||
|
@ -859,8 +863,14 @@ strio_read(argc, argv, self)
|
||||||
olen = -1;
|
olen = -1;
|
||||||
len = RSTRING(ptr->string)->len;
|
len = RSTRING(ptr->string)->len;
|
||||||
if (len <= ptr->pos) {
|
if (len <= ptr->pos) {
|
||||||
if (ptr->flags & STRIO_EOF) return Qnil;
|
ptr->flags |= STRIO_EOF;
|
||||||
len = 0;
|
if (NIL_P(str)) {
|
||||||
|
str = rb_str_new(0, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_str_resize(str, 0);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
len -= ptr->pos;
|
len -= ptr->pos;
|
||||||
|
@ -869,7 +879,15 @@ strio_read(argc, argv, self)
|
||||||
default:
|
default:
|
||||||
rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
|
rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
|
||||||
}
|
}
|
||||||
|
if (NIL_P(str)) {
|
||||||
str = rb_str_substr(ptr->string, ptr->pos, len);
|
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 (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);
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче