[macruby-changes] [4907] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 15 19:05:59 PST 2010
Revision: 4907
http://trac.macosforge.org/projects/ruby/changeset/4907
Author: watson1978 at gmail.com
Date: 2010-11-15 19:05:55 -0800 (Mon, 15 Nov 2010)
Log Message:
-----------
ARGF.getc will be passed the multiple file path.
Test Script:
{{{
require 'tempfile'
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
t1 = Tempfile.new("foo")
t1.puts "1"
t1.puts "2"
t1.close
t2 = Tempfile.new("bar")
t2.puts "3"
t2.puts "4"
t2.close
def ruby(*args)
args = ['-e', '$>.write($<.read)'] if args.empty?
ruby = ARGV[0] || "/usr/local/bin/macruby"
f = IO.popen([ruby] + args, 'r+')
yield(f)
ensure
f.close unless !f || f.closed?
end
ruby('-e', <<-SRC, t1.path, t2.path) do |f|
s = ""
while c = ARGF.getc
s << c
end
puts s
SRC
assert_equal("1\n2\n3\n4\n", f.read)
end
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-11-15 23:36:47 UTC (rev 4906)
+++ MacRuby/trunk/io.c 2010-11-16 03:05:55 UTC (rev 4907)
@@ -4344,9 +4344,25 @@
static VALUE
argf_getc(VALUE argf, SEL sel)
{
- next_argv();
- ARGF_FORWARD(0, 0);
- return rb_io_getc(ARGF.current_file, 0);
+ VALUE ch;
+
+ retry:
+ if (!next_argv()) {
+ return Qnil;
+ }
+ if (ARGF_GENERIC_INPUT_P()) {
+ ch = rb_funcall3(ARGF.current_file, rb_intern("getc"), 0, 0);
+ }
+ else {
+ ch = rb_io_getc(ARGF.current_file, sel);
+ }
+ if (NIL_P(ch) && ARGF.next_p != -1) {
+ argf_close(ARGF.current_file, sel);
+ ARGF.next_p = 1;
+ goto retry;
+ }
+
+ return ch;
}
static VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101115/74bda694/attachment-0001.html>
More information about the macruby-changes
mailing list