[macruby-changes] [4869] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 1 17:23:12 PDT 2010
Revision: 4869
http://trac.macosforge.org/projects/ruby/changeset/4869
Author: watson1978 at gmail.com
Date: 2010-11-01 17:23:10 -0700 (Mon, 01 Nov 2010)
Log Message:
-----------
IO#gets(nil, limit) will return data of limited length.
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))
r, w = IO.pipe
w << "0123456789\n0123456789"
w.close
assert_equal("0123456789\n0123456789", r.gets(nil, 30))
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-11-01 23:13:05 UTC (rev 4868)
+++ MacRuby/trunk/io.c 2010-11-02 00:23:10 UTC (rev 4869)
@@ -1386,9 +1386,14 @@
VALUE bstr = rb_bstr_new();
if (NIL_P(sep)) {
rb_io_read_all(io_struct, bstr);
- if (rb_bstr_length(bstr) == 0) {
+
+ long length = rb_bstr_length(bstr);
+ if (length == 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/78cc3b45/attachment.html>
More information about the macruby-changes
mailing list