[macruby-changes] [4791] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 13 00:44:05 PDT 2010
Revision: 4791
http://trac.macosforge.org/projects/ruby/changeset/4791
Author: watson1978 at gmail.com
Date: 2010-10-13 00:44:01 -0700 (Wed, 13 Oct 2010)
Log Message:
-----------
Fixed a bug of IO#sysread(length). Should return empty string when specified 0 to length.
Test Script:
{{{
file = "tmp.txt"
File.open(file, "w") {|f| f.write "hello"}
File.open(file) {|f|
s = "xxx"
t = f.sysread(0, s)
p s == ""
p t == ""
p s.object_id == t.object_id
t = f.sysread(0)
p t == ""
}
File.delete(file)
}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-10-13 03:51:05 UTC (rev 4790)
+++ MacRuby/trunk/io.c 2010-10-13 07:44:01 UTC (rev 4791)
@@ -1135,10 +1135,6 @@
// TODO: throw error if the buffer is not empty;
- if (to_read == 0) {
- return INT2FIX(0);
- }
-
if (!NIL_P(buffer)) {
// TODO: throw an error if the provided string can't be modified in place
buffer = rb_str_bstr(rb_obj_as_string(buffer));
@@ -1146,10 +1142,14 @@
else {
buffer = rb_bstr_new();
}
- rb_bstr_resize(buffer, to_read);
-
+ rb_bstr_resize(buffer, to_read);
+
+ if (to_read == 0) {
+ return buffer;
+ }
+
uint8_t *bytes = rb_bstr_bytes(buffer);
-
+
const long r = read(io->read_fd, bytes, (size_t)to_read);
if (r == -1) {
rb_sys_fail("read(2) failed.");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101013/1f2be956/attachment.html>
More information about the macruby-changes
mailing list