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

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 15 19:06:09 PST 2010


Revision: 4910
          http://trac.macosforge.org/projects/ruby/changeset/4910
Author:   watson1978 at gmail.com
Date:     2010-11-15 19:06:07 -0800 (Mon, 15 Nov 2010)
Log Message:
-----------
ARGF.getbyte 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.getbyte
    s << c
  end
  p s
SRC
  assert_equal("[49, 10, 50, 10, 51, 10, 52, 10]\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:03 UTC (rev 4909)
+++ MacRuby/trunk/io.c	2010-11-16 03:06:07 UTC (rev 4910)
@@ -4417,9 +4417,25 @@
 static VALUE
 argf_getbyte(VALUE argf, SEL sel)
 {
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    return rb_io_getbyte(ARGF.current_file, 0);
+    VALUE ch;
+
+  retry:
+    if (!next_argv()) {
+	return Qnil;
+    }
+    if (TYPE(ARGF.current_file) != T_FILE) {
+	ch = rb_funcall3(ARGF.current_file, rb_intern("getbyte"), 0, 0);
+    }
+    else {
+	ch = rb_io_getbyte(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/812a8b2a/attachment.html>


More information about the macruby-changes mailing list