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

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 15 21:05:22 PST 2010


Revision: 4913
          http://trac.macosforge.org/projects/ruby/changeset/4913
Author:   watson1978 at gmail.com
Date:     2010-11-15 21:05:19 -0800 (Mon, 15 Nov 2010)
Log Message:
-----------
ARGF.readline 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|
  begin
    s = []
    while l = ARGF.readline
      s << l
    end
  rescue EOFError
    p s
  end
SRC
  assert_equal("[\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\"]\n", f.read)
end

puts :ok
}}}

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

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2010-11-16 03:06:14 UTC (rev 4912)
+++ MacRuby/trunk/io.c	2010-11-16 05:05:19 UTC (rev 4913)
@@ -3513,9 +3513,18 @@
 static VALUE
 argf_readline(VALUE argf, SEL sel, int argc, VALUE *argv)
 {
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    return rb_io_readline(ARGF.current_file, sel, argc, argv);
+    VALUE line;
+
+    if (!next_argv()) {
+	rb_eof_error();
+    }
+    ARGF_FORWARD(argc, argv);
+    line = argf_gets(argf, sel, argc, argv);
+    if (NIL_P(line)) {
+	rb_eof_error();
+    }
+
+    return line;
 }
 
 static VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101115/f32be2e7/attachment.html>


More information about the macruby-changes mailing list