summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-03 11:40:41 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-03 11:40:41 +0000
commited5b6231dfa960dc1cec83b38109da95fc11cb5f (patch)
tree3eda0dec5addb4519076beb04a297f106e99d2d8
parent5665cf676f2587af86be584126453cd7f5880758 (diff)
merges r22610 from trunk into ruby_1_9_1.
-- * io.c (rb_io_getline_1): enables limit even if rs is given. [ruby-core:22434] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@22740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--io.c32
-rw-r--r--test/ruby/test_io.rb3
3 files changed, 24 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 6761aa400b..2586326afc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Feb 25 12:06:09 2009 <nobu@ruby-lang.org>
+
+ * io.c (rb_io_getline_1): enables limit even if rs is given.
+ [ruby-core:22434]
+
Wed Feb 25 02:28:51 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_chomp_bang): coderange may change.
diff --git a/io.c b/io.c
index 80482bf5fa..e3b6281562 100644
--- a/io.c
+++ b/io.c
@@ -2215,7 +2215,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
- if (NIL_P(rs)) {
+ if (NIL_P(rs) && limit < 0) {
str = read_all(fptr, 0, Qnil);
if (RSTRING_LEN(str) == 0) return Qnil;
}
@@ -2227,24 +2227,26 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
return rb_io_getline_fast(fptr, enc);
}
else {
- int c, newline;
- const char *rsptr;
- long rslen;
+ int c, newline = -1;
+ const char *rsptr = 0;
+ long rslen = 0;
int rspara = 0;
int extra_limit = 16;
- rslen = RSTRING_LEN(rs);
- if (rslen == 0) {
- rsptr = "\n\n";
- rslen = 2;
- rspara = 1;
- swallow(fptr, '\n');
- rs = 0;
- }
- else {
- rsptr = RSTRING_PTR(rs);
+ if (!NIL_P(rs)) {
+ rslen = RSTRING_LEN(rs);
+ if (rslen == 0) {
+ rsptr = "\n\n";
+ rslen = 2;
+ rspara = 1;
+ swallow(fptr, '\n');
+ rs = 0;
+ }
+ else {
+ rsptr = RSTRING_PTR(rs);
+ }
+ newline = (unsigned char)rsptr[rslen - 1];
}
- newline = (unsigned char)rsptr[rslen - 1];
/* MS - Optimisation */
enc = io_read_encoding(fptr);
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 073ca20314..9082b76b61 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -61,8 +61,9 @@ class TestIO < Test::Unit::TestCase
def test_gets_limit_extra_arg
with_pipe {|r, w|
r, w = IO.pipe
- w << "0123456789"
+ w << "0123456789\n0123456789"
w.close
+ assert_equal("0123456789\n0", r.gets(nil, 12))
assert_raise(TypeError) { r.gets(3,nil) }
}
end