Project

General

Profile

Feature #14042 ยป ruby-changes.patch

Updated patch file - rohitpaulk (Paul Kuruvilla), 10/23/2017 12:06 PM

View differences:

io.c (working copy)
1730 1730
    return rb_funcallv(io, id_write, 1, &str);
1731 1731
}
1732 1732

  
1733
VALUE
1734
rb_io_writev(VALUE io, int argc, VALUE *argv)
1735
{
1736
    return rb_funcallv(io, id_write, argc, argv);
1737
}
1738

  
1733 1739
/*
1734 1740
 *  call-seq:
1735 1741
 *     ios << obj     -> ios
......
7586 7592
    return Qtrue;
7587 7593
}
7588 7594

  
7595
void
7596
io_puts_string(VALUE out, VALUE str)
7597
{
7598
    if (RSTRING_LEN(str) == 0 || !rb_str_end_with_asciichar(str, '\n')) {
7599
#ifdef HAVE_WRITEV
7600
        VALUE args[2];
7601
        args[0] = str;
7602
        args[1] = rb_default_rs;
7603
        rb_io_writev(out, 2, args);
7604
#else
7605
        rb_io_write(out, str);
7606
        rb_io_write(out, rb_default_rs);
7607
#endif
7608
    }
7609
    else {
7610
        rb_io_write(out, str);
7611
    }
7612
}
7613

  
7589 7614
/*
7590 7615
 *  call-seq:
7591 7616
 *     ios.puts(obj, ...)    -> nil
......
7617 7642
rb_io_puts(int argc, const VALUE *argv, VALUE out)
7618 7643
{
7619 7644
    int i;
7620
    VALUE line;
7621 7645

  
7622 7646
    /* if no argument given, print newline. */
7623 7647
    if (argc == 0) {
7624
	rb_io_write(out, rb_default_rs);
7625
	return Qnil;
7648
        rb_io_write(out, rb_default_rs);
7649
        return Qnil;
7626 7650
    }
7627 7651
    for (i=0; i<argc; i++) {
7628
	if (RB_TYPE_P(argv[i], T_STRING)) {
7629
	    line = argv[i];
7630
	    goto string;
7631
	}
7632
	if (rb_exec_recursive(io_puts_ary, argv[i], out)) {
7633
	    continue;
7634
	}
7635
	line = rb_obj_as_string(argv[i]);
7636
      string:
7637
	rb_io_write(out, line);
7638
	if (RSTRING_LEN(line) == 0 ||
7639
            !rb_str_end_with_asciichar(line, '\n')) {
7640
	    rb_io_write(out, rb_default_rs);
7641
	}
7652
        if (RB_TYPE_P(argv[i], T_STRING)) {
7653
            io_puts_string(out, argv[i]);
7654
            continue;
7655
        }
7656

  
7657
        if (rb_exec_recursive(io_puts_ary, argv[i], out)) {
7658
            continue;
7659
        }
7660

  
7661
        io_puts_string(out, rb_obj_as_string(argv[i]));
7642 7662
    }
7643 7663

  
7644 7664
    return Qnil;
test/mkmf/base.rb (working copy)
49 49
    def filter(&block)
50 50
      @filter = block
51 51
    end
52
    def write(s)
52
    def write(*args)
53 53
      if @out
54
        @buffer << s
54
        @buffer << args.join
55 55
      elsif @origin
56
        @origin << s
56
        @origin << args.join
57 57
      end
58 58
    end
59 59
  end
test/ruby/test_io.rb (working copy)
2427 2427
    end)
2428 2428
  end
2429 2429

  
2430
  def test_puts_parallel
2431
    pipe(proc do |w|
2432
      threads = []
2433
      100.times do
2434
        threads << Thread.new { w.puts "hey" }
2435
      end
2436
      threads.each(&:join)
2437
      w.close
2438
    end, proc do |r|
2439
      assert_equal("hey\n" * 100, r.read)
2440
    end)
2441
  end
2442

  
2430 2443
  def test_display
2431 2444
    pipe(proc do |w|
2432 2445
      "foo".display(w)