[macruby-changes] [4904] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 15 00:12:24 PST 2010
Revision: 4904
http://trac.macosforge.org/projects/ruby/changeset/4904
Author: watson1978 at gmail.com
Date: 2010-11-15 00:12:19 -0800 (Mon, 15 Nov 2010)
Log Message:
-----------
fixed the pipeline within IO.readlines.
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
a = IO.readlines("|/usr/bin/ruby -e 'puts :foo; puts :bar; puts :baz'")
assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = []
IO.foreach("|/usr/bin/ruby -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x}
assert_equal(["foo\n", "bar\n", "baz\n"], a)
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-11-14 05:18:57 UTC (rev 4903)
+++ MacRuby/trunk/io.c 2010-11-15 08:12:19 UTC (rev 4904)
@@ -2354,14 +2354,21 @@
}
static VALUE
+io_pipe_open(VALUE prog, VALUE mode)
+{
+ if (NIL_P(mode)) {
+ mode = (VALUE)CFSTR("r");
+ }
+ return io_from_spawning_new_process(prog, mode);
+}
+
+static VALUE
rb_io_s_popen(VALUE klass, SEL sel, int argc, VALUE *argv)
{
VALUE process_name, mode;
rb_scan_args(argc, argv, "11", &process_name, &mode);
- if (NIL_P(mode)) {
- mode = (VALUE)CFSTR("r");
- }
- VALUE io = io_from_spawning_new_process(process_name, mode);
+
+ VALUE io = io_pipe_open(process_name, mode);
if (rb_block_given_p()) {
VALUE ret = rb_vm_yield(1, &io);
rb_io_close(io);
@@ -2529,7 +2536,8 @@
if (argc >= 1) {
VALUE cmd = check_pipe_command(argv[0]);
if (cmd != Qnil) {
- return rb_io_s_popen(rb_cIO, 0, 1, &cmd);
+ VALUE modes = (argc >= 2) ? argv[1] : Qnil;
+ return io_pipe_open(cmd, modes);
}
}
VALUE path, modes, permissions;
@@ -4067,12 +4075,6 @@
rb_scan_args(argc, argv, "13", &fname, NULL, NULL, NULL);
struct foreach_arg arg;
- FilePathValue(fname);
- VALUE cmd = check_pipe_command(fname);
- if (cmd != Qnil) {
- // TODO: pipe not support yet.
- rb_notimplement();
- }
arg.io = rb_file_open(io_alloc(recv, 0), 1, &fname);
arg.argc = argc - 1;
arg.argv = argv + 1;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101115/cab07398/attachment.html>
More information about the macruby-changes
mailing list