mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/stringio/stringio.c (strio_read): return new string if nil
is explicitly given as a buffer ([Bug #5207]), otherwise set the encoding. also removed dead code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e9930a4b56
commit
dcb7cc1a8b
3 changed files with 26 additions and 10 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Sat Aug 20 10:43:24 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/stringio/stringio.c (strio_read): return new string if nil
|
||||||
|
is explicitly given as a buffer ([Bug #5207]), otherwise set the
|
||||||
|
encoding. also removed dead code.
|
||||||
|
|
||||||
Fri Aug 19 14:25:51 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Aug 19 14:25:51 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* process.c (proc_spawn_v, proc_spawn): should not wait the
|
* process.c (proc_spawn_v, proc_spawn): should not wait the
|
||||||
|
|
|
@ -1219,12 +1219,15 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
||||||
struct StringIO *ptr = readable(StringIO(self));
|
struct StringIO *ptr = readable(StringIO(self));
|
||||||
VALUE str = Qnil;
|
VALUE str = Qnil;
|
||||||
long len;
|
long len;
|
||||||
|
int binary = 0;
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 2:
|
case 2:
|
||||||
str = argv[1];
|
str = argv[1];
|
||||||
StringValue(str);
|
if (!NIL_P(str)) {
|
||||||
rb_str_modify(str);
|
StringValue(str);
|
||||||
|
rb_str_modify(str);
|
||||||
|
}
|
||||||
case 1:
|
case 1:
|
||||||
if (!NIL_P(argv[0])) {
|
if (!NIL_P(argv[0])) {
|
||||||
len = NUM2LONG(argv[0]);
|
len = NUM2LONG(argv[0]);
|
||||||
|
@ -1235,6 +1238,7 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
||||||
if (!NIL_P(str)) rb_str_resize(str, 0);
|
if (!NIL_P(str)) rb_str_resize(str, 0);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
binary = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
@ -1258,21 +1262,19 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
||||||
}
|
}
|
||||||
if (NIL_P(str)) {
|
if (NIL_P(str)) {
|
||||||
str = strio_substr(ptr, ptr->pos, len);
|
str = strio_substr(ptr, ptr->pos, len);
|
||||||
if (argc > 0) rb_enc_associate(str, rb_ascii8bit_encoding());
|
if (binary) rb_enc_associate(str, rb_ascii8bit_encoding());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
long rest = RSTRING_LEN(ptr->string) - ptr->pos;
|
long rest = RSTRING_LEN(ptr->string) - ptr->pos;
|
||||||
if (len > rest) len = rest;
|
if (len > rest) len = rest;
|
||||||
rb_str_resize(str, len);
|
rb_str_resize(str, len);
|
||||||
MEMCPY(RSTRING_PTR(str), RSTRING_PTR(ptr->string) + ptr->pos, char, len);
|
MEMCPY(RSTRING_PTR(str), RSTRING_PTR(ptr->string) + ptr->pos, char, len);
|
||||||
|
if (binary)
|
||||||
|
rb_enc_associate(str, rb_ascii8bit_encoding());
|
||||||
|
else
|
||||||
|
rb_enc_copy(str, ptr->string);
|
||||||
}
|
}
|
||||||
if (NIL_P(str)) {
|
ptr->pos += RSTRING_LEN(str);
|
||||||
str = rb_str_new(0, 0);
|
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ptr->pos += len = RSTRING_LEN(str);
|
|
||||||
}
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -418,6 +418,14 @@ class TestStringIO < Test::Unit::TestCase
|
||||||
assert_equal("\u3042\u3044", f.read)
|
assert_equal("\u3042\u3044", f.read)
|
||||||
f.rewind
|
f.rewind
|
||||||
assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.read(f.size))
|
assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.read(f.size))
|
||||||
|
|
||||||
|
bug5207 = '[ruby-core:39026]'
|
||||||
|
f.rewind
|
||||||
|
assert_equal("\u3042\u3044", f.read(nil, nil), bug5207)
|
||||||
|
f.rewind
|
||||||
|
s = ""
|
||||||
|
f.read(nil, s)
|
||||||
|
assert_equal("\u3042\u3044", s, bug5207)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readpartial
|
def test_readpartial
|
||||||
|
|
Loading…
Reference in a new issue