Feature #14042 ยป ruby-changes.patch
| io.c (working copy) | ||
|---|---|---|
|
return rb_funcallv(io, id_write, 1, &str);
|
||
|
}
|
||
|
VALUE
|
||
|
rb_io_writev(VALUE io, int argc, VALUE *argv)
|
||
|
{
|
||
|
return rb_funcallv(io, id_write, argc, argv);
|
||
|
}
|
||
|
/*
|
||
|
* call-seq:
|
||
|
* ios << obj -> ios
|
||
| ... | ... | |
|
return Qtrue;
|
||
|
}
|
||
|
void
|
||
|
io_puts_string(VALUE out, VALUE str)
|
||
|
{
|
||
|
if (RSTRING_LEN(str) == 0 || !rb_str_end_with_asciichar(str, '\n')) {
|
||
|
#ifdef HAVE_WRITEV
|
||
|
VALUE args[2];
|
||
|
args[0] = str;
|
||
|
args[1] = rb_default_rs;
|
||
|
rb_io_writev(out, 2, args);
|
||
|
#else
|
||
|
rb_io_write(out, str);
|
||
|
rb_io_write(out, rb_default_rs);
|
||
|
#endif
|
||
|
}
|
||
|
else {
|
||
|
rb_io_write(out, str);
|
||
|
}
|
||
|
}
|
||
|
/*
|
||
|
* call-seq:
|
||
|
* ios.puts(obj, ...) -> nil
|
||
| ... | ... | |
|
rb_io_puts(int argc, const VALUE *argv, VALUE out)
|
||
|
{
|
||
|
int i;
|
||
|
VALUE line;
|
||
|
/* if no argument given, print newline. */
|
||
|
if (argc == 0) {
|
||
|
rb_io_write(out, rb_default_rs);
|
||
|
return Qnil;
|
||
|
rb_io_write(out, rb_default_rs);
|
||
|
return Qnil;
|
||
|
}
|
||
|
for (i=0; i<argc; i++) {
|
||
|
if (RB_TYPE_P(argv[i], T_STRING)) {
|
||
|
line = argv[i];
|
||
|
goto string;
|
||
|
}
|
||
|
if (rb_exec_recursive(io_puts_ary, argv[i], out)) {
|
||
|
continue;
|
||
|
}
|
||
|
line = rb_obj_as_string(argv[i]);
|
||
|
string:
|
||
|
rb_io_write(out, line);
|
||
|
if (RSTRING_LEN(line) == 0 ||
|
||
|
!rb_str_end_with_asciichar(line, '\n')) {
|
||
|
rb_io_write(out, rb_default_rs);
|
||
|
}
|
||
|
if (RB_TYPE_P(argv[i], T_STRING)) {
|
||
|
io_puts_string(out, argv[i]);
|
||
|
continue;
|
||
|
}
|
||
|
if (rb_exec_recursive(io_puts_ary, argv[i], out)) {
|
||
|
continue;
|
||
|
}
|
||
|
io_puts_string(out, rb_obj_as_string(argv[i]));
|
||
|
}
|
||
|
return Qnil;
|
||
| test/mkmf/base.rb (working copy) | ||
|---|---|---|
|
def filter(&block)
|
||
|
@filter = block
|
||
|
end
|
||
|
def write(s)
|
||
|
def write(*args)
|
||
|
if @out
|
||
|
@buffer << s
|
||
|
@buffer << args.join
|
||
|
elsif @origin
|
||
|
@origin << s
|
||
|
@origin << args.join
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| test/ruby/test_io.rb (working copy) | ||
|---|---|---|
|
end)
|
||
|
end
|
||
|
def test_puts_parallel
|
||
|
pipe(proc do |w|
|
||
|
threads = []
|
||
|
100.times do
|
||
|
threads << Thread.new { w.puts "hey" }
|
||
|
end
|
||
|
threads.each(&:join)
|
||
|
w.close
|
||
|
end, proc do |r|
|
||
|
assert_equal("hey\n" * 100, r.read)
|
||
|
end)
|
||
|
end
|
||
|
def test_display
|
||
|
pipe(proc do |w|
|
||
|
"foo".display(w)
|
||