[macruby-changes] [5024] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Tue Dec 14 00:45:50 PST 2010
Revision: 5024
http://trac.macosforge.org/projects/ruby/changeset/5024
Author: watson1978 at gmail.com
Date: 2010-12-14 00:45:45 -0800 (Tue, 14 Dec 2010)
Log Message:
-----------
IO.open(path) will handle a file descriptor when path is numeric.
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
FILE = "tmp.xxxx.txt"
f1 = File.open(FILE, "w+")
f1.puts "hello world!"
f1.pos = 0
f2 = File.open(f1.fileno)
assert_equal(f1.fileno, f2.fileno)
assert_equal("hello world!\n", f2.read)
assert_raise(Errno::EBADF) { File.new(30000) }
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-12-14 06:36:28 UTC (rev 5023)
+++ MacRuby/trunk/io.c 2010-12-14 08:45:45 UTC (rev 5024)
@@ -3188,6 +3188,14 @@
static VALUE
rb_file_initialize(VALUE io, SEL sel, int argc, VALUE *argv)
{
+ if (0 < argc && argc < 3) {
+ VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int");
+
+ if (!NIL_P(fd)) {
+ argv[0] = fd;
+ return rb_io_initialize(io, sel, argc, argv);
+ }
+ }
return rb_file_open(io, argc, argv);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101214/d970b711/attachment-0001.html>
More information about the macruby-changes
mailing list