[macruby-changes] [4870] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 1 18:17:59 PDT 2010
Revision: 4870
http://trac.macosforge.org/projects/ruby/changeset/4870
Author: watson1978 at gmail.com
Date: 2010-11-01 18:17:57 -0700 (Mon, 01 Nov 2010)
Log Message:
-----------
r4869 mistook, IO#gets(nil, limit) should not read all data from the stream.
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
string = "a\n\nb\n\n"
r, w = IO.pipe
w.print string
w.close
assert_equal(string, r.gets(nil))
r.close
r, w = IO.pipe
w << "0123456789\n0123456789"
w.close
assert_equal("0123456789\n0", r.gets(nil, 12))
assert_equal("123456789", r.gets)
r, w = IO.pipe
w << "0123456789\n0123456789"
w.close
assert_equal("0123456789\n0123456789", r.gets(nil, 30))
puts :ok
}}}
Revision Links:
--------------
http://trac.macosforge.org/projects/ruby/changeset/4869
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-11-02 00:23:10 UTC (rev 4869)
+++ MacRuby/trunk/io.c 2010-11-02 01:17:57 UTC (rev 4870)
@@ -1385,15 +1385,18 @@
VALUE bstr = rb_bstr_new();
if (NIL_P(sep)) {
- rb_io_read_all(io_struct, bstr);
-
- long length = rb_bstr_length(bstr);
- if (length == 0) {
+ if (line_limit != -1) {
+ rb_bstr_resize(bstr, line_limit);
+ uint8_t *bytes = rb_bstr_bytes(bstr);
+ long r = rb_io_read_internal(io_struct, bytes, line_limit);
+ rb_bstr_set_length(bstr, r);
+ }
+ else {
+ rb_io_read_all(io_struct, bstr);
+ }
+ if (rb_bstr_length(bstr) == 0) {
return Qnil;
}
- if (line_limit >= 0 && line_limit < length) {
- rb_bstr_set_length(bstr, line_limit);
- }
}
else if (line_limit != -1) {
rb_bstr_resize(bstr, line_limit);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101101/e9dcab5e/attachment-0001.html>
More information about the macruby-changes
mailing list