[macruby-changes] [5025] MacRuby/trunk/io.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Dec 14 03:36:06 PST 2010


Revision: 5025
          http://trac.macosforge.org/projects/ruby/changeset/5025
Author:   watson1978 at gmail.com
Date:     2010-12-14 03:36:02 -0800 (Tue, 14 Dec 2010)
Log Message:
-----------
When passed the numerical value to path and mode with IO.open(path, mode), MacRuby crashed.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

FILE = "tmp.xxxx.txt"
flags = File::CREAT | File::TRUNC | File::WRONLY

f = File.new(FILE, "w")
f.close

f = File.new(FILE)
File.new(f.fileno, flags)

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/io.c

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2010-12-14 08:45:45 UTC (rev 5024)
+++ MacRuby/trunk/io.c	2010-12-14 11:36:02 UTC (rev 5025)
@@ -3144,8 +3144,16 @@
 	rb_sys_fail(0);
     }
 
-    mode_flags = (NIL_P(mode) ? FMODE_READABLE
-	    : convert_mode_string_to_fmode(mode));
+    if (NIL_P(mode)) {
+	mode_flags = FMODE_READABLE;
+    }
+    else if (TYPE(mode) == T_STRING) {
+	mode_flags = convert_mode_string_to_fmode(mode);
+    }
+    else {
+	mode_flags = NUM2INT(mode);
+    }
+
     prepare_io_from_fd(io_struct, fd, mode_flags);
     return io;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101214/3c4a3d91/attachment.html>


More information about the macruby-changes mailing list