[MacRuby] #852: IO#read should return "" in outbuf when calls the IO#read(length, outbuf) with position of Discriptor == EOF.
MacRuby
ruby-noreply at macosforge.org
Tue Aug 17 01:40:28 PDT 2010
#852: IO#read should return "" in outbuf when calls the IO#read(length, outbuf)
with position of Discriptor == EOF.
----------------------------------+-----------------------------------------
Reporter: watson1978@… | Owner: lsansonetti@…
Type: defect | Status: new
Priority: blocker | Milestone:
Component: MacRuby | Keywords:
----------------------------------+-----------------------------------------
Test Script:
{{{
$ cat test_eof.rb
require "tempfile"
def open_file(content)
f = Tempfile.new("test-eof")
f << content
f.rewind
yield f
end
open_file("") {|f|
s = "x"
p f.read(100, s) # => nil
p s # => ""
}
puts "----------"
open_file("hello world") {|f|
s = "x"
p f.read(100, s) # => "hello world"
p f.read(100, s) # => nil
p s # => ""
}
}}}
Result of Ruby 1.9.1:
{{{
$ ruby test_eof.rb
nil
""
----------
"hello world"
nil
""
}}}
Result of MacRuby Trunk:
{{{
$ VM_DISABLE_RBO=true DYLD_LIBRARY_PATH=. ./macruby -I./lib test_eof.rb
nil
"x\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
----------
"hello world"
nil
"hello
world\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
}}}
When rb_io_read_internal() returns 0 with io_read(), I think that it is
necessary to execute the rb_bstr_set_length() as that length of outbuf is
0.
{{{
#!diff
diff --git a/io.c b/io.c
index b3bee84..51f01b0 100644
--- a/io.c
+++ b/io.c
@@ -1220,10 +1220,11 @@ io_read(VALUE io, SEL sel, int argc, VALUE *argv)
uint8_t *bytes = rb_bstr_bytes(outbuf);
const long data_read = rb_io_read_internal(io_struct, bytes, size);
+ rb_bstr_set_length(outbuf, data_read);
+
if (data_read == 0) {
return Qnil;
}
- rb_bstr_set_length(outbuf, data_read);
return outbuf;
}
}}}
--
Ticket URL: <http://www.macruby.org/trac/ticket/852>
MacRuby <http://macruby.org/>
More information about the macruby-tickets
mailing list