mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/stringio/stringio.c (strio_getline): check whether str is
a string when str and lim are given. https://twitter.com/watson1978/status/56225052152168449 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4ca9e7d03a
commit
653b4248a3
3 changed files with 22 additions and 12 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Fri Apr 8 16:01:56 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/stringio/stringio.c (strio_getline): check whether str is
|
||||||
|
a string when str and lim are given.
|
||||||
|
https://twitter.com/watson1978/status/56225052152168449
|
||||||
|
|
||||||
Thu Apr 7 20:03:52 2011 Tanaka Akira <akr@fsij.org>
|
Thu Apr 7 20:03:52 2011 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* include/ruby/io.h: parenthesize macro arguments.
|
* include/ruby/io.h: parenthesize macro arguments.
|
||||||
|
|
|
@ -921,18 +921,17 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
|
||||||
{
|
{
|
||||||
const char *s, *e, *p;
|
const char *s, *e, *p;
|
||||||
long n, limit = 0;
|
long n, limit = 0;
|
||||||
VALUE str;
|
VALUE str, lim;
|
||||||
|
|
||||||
if (argc == 0) {
|
rb_scan_args(argc, argv, "02", &str, &lim);
|
||||||
|
switch (argc) {
|
||||||
|
case 0:
|
||||||
str = rb_rs;
|
str = rb_rs;
|
||||||
}
|
break;
|
||||||
else {
|
|
||||||
VALUE lim, tmp;
|
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "11", &str, &lim);
|
case 1:
|
||||||
if (!NIL_P(lim)) limit = NUM2LONG(lim);
|
if (!NIL_P(str) && TYPE(str) != T_STRING) {
|
||||||
else if (!NIL_P(str) && TYPE(str) != T_STRING) {
|
VALUE tmp = rb_check_string_type(str);
|
||||||
tmp = rb_check_string_type(str);
|
|
||||||
if (NIL_P(tmp)) {
|
if (NIL_P(tmp)) {
|
||||||
limit = NUM2LONG(str);
|
limit = NUM2LONG(str);
|
||||||
if (limit == 0) return rb_str_new(0,0);
|
if (limit == 0) return rb_str_new(0,0);
|
||||||
|
@ -942,9 +941,12 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
|
||||||
str = tmp;
|
str = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!NIL_P(str)) {
|
break;
|
||||||
StringValue(str);
|
|
||||||
}
|
case 2:
|
||||||
|
if (!NIL_P(str)) StringValue(str);
|
||||||
|
limit = NUM2LONG(lim);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr->pos >= (n = RSTRING_LEN(ptr->string))) {
|
if (ptr->pos >= (n = RSTRING_LEN(ptr->string))) {
|
||||||
|
|
|
@ -51,6 +51,8 @@ class TestStringIO < Test::Unit::TestCase
|
||||||
assert_equal("abc\n", StringIO.new("abc\n\ndef\n").gets)
|
assert_equal("abc\n", StringIO.new("abc\n\ndef\n").gets)
|
||||||
assert_equal("abc\n\ndef\n", StringIO.new("abc\n\ndef\n").gets(nil))
|
assert_equal("abc\n\ndef\n", StringIO.new("abc\n\ndef\n").gets(nil))
|
||||||
assert_equal("abc\n\n", StringIO.new("abc\n\ndef\n").gets(""))
|
assert_equal("abc\n\n", StringIO.new("abc\n\ndef\n").gets(""))
|
||||||
|
assert_raise(TypeError){StringIO.new("").gets(1, 1)}
|
||||||
|
assert_raise(TypeError){StringIO.new("").gets(nil, nil)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readlines
|
def test_readlines
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue