[macruby-changes] [4880] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Nov 4 07:06:45 PDT 2010
Revision: 4880
http://trac.macosforge.org/projects/ruby/changeset/4880
Author: watson1978 at gmail.com
Date: 2010-11-04 07:06:42 -0700 (Thu, 04 Nov 2010)
Log Message:
-----------
When there was a delimiter before than limit, IO#gets(limit) returned broken string at next call.
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
string = "0123\n45\n6789ab\ncdef"
r, w = IO.pipe
w.print string
w.close
assert_equal("0123\n", r.gets(6))
assert_equal("45\n", r.gets(6))
assert_equal("6789ab", r.gets(6))
assert_equal("\n", r.gets(6))
assert_equal("cdef", r.gets(6))
assert_equal(nil, r.gets(6))
r.close
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-11-04 10:49:30 UTC (rev 4879)
+++ MacRuby/trunk/io.c 2010-11-04 14:06:42 UTC (rev 4880)
@@ -1410,8 +1410,13 @@
if (range.location != kCFNotFound) {
rb_io_create_buf(io_struct);
long rest_size = r - (range.location + 1);
- CFDataAppendBytes(io_struct->buf, bytes + range.location + 1,
- rest_size);
+ if (rest_size > 0 && line_limit > r) {
+ CFDataAppendBytes(io_struct->buf, bytes + range.location + 1,
+ rest_size);
+ }
+ else {
+ io_struct->buf_offset -= rest_size;
+ }
r = range.location + 1;
}
// Resize the buffer to whatever was actually read (can be different
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101104/89855db3/attachment.html>
More information about the macruby-changes
mailing list