ruby-changes:44343
From: nobu <ko1@a...>
Date: Thu, 13 Oct 2016 19:41:39 +0900 (JST)
Subject: [ruby-changes:44343] nobu:r56416 (trunk): io.c: copy_stream to duplex IO
nobu 2016-10-13 19:41:34 +0900 (Thu, 13 Oct 2016) New Revision: 56416 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56416 Log: io.c: copy_stream to duplex IO * io.c (copy_stream_body): use IO to write to copy to duplex IO. http://twitter.com/knu/status/786505317974585344 Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 56415) +++ test/ruby/test_io.rb (revision 56416) @@ -1105,6 +1105,18 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L1105 } end + def test_copy_stream_to_duplex_io + result = IO.pipe {|a,w| + Thread.start {w.puts "yes"; w.close} + IO.popen([EnvUtil.rubybin, '-pe$_="#$.:#$_"'], "r+") {|b| + IO.copy_stream(a, b) + b.close_write + b.read + } + } + assert_equal("1:yes\n", result) + end + def ruby(*args) args = ['-e', '$>.write($<.read)'] if args.empty? ruby = EnvUtil.rubybin Index: ChangeLog =================================================================== --- ChangeLog (revision 56415) +++ ChangeLog (revision 56416) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Oct 13 19:41:32 2016 Nobuyoshi Nakada <nobu@r...> + + * io.c (copy_stream_body): use IO to write to copy to duplex IO. + http://twitter.com/knu/status/786505317974585344 + Thu Oct 13 17:05:57 2016 Dwain Faithfull <dwfaithfull@g...> * hash.c (rb_hash_compact, rb_hash_compact_bang): Removes nil Index: io.c =================================================================== --- io.c (revision 56415) +++ io.c (revision 56416) @@ -10657,7 +10657,7 @@ copy_stream_body(VALUE arg) https://github.com/ruby/ruby/blob/trunk/io.c#L10657 else { VALUE tmp_io = rb_io_check_io(dst_io); if (!NIL_P(tmp_io)) { - dst_io = tmp_io; + dst_io = GetWriteIO(tmp_io); } else if (!RB_TYPE_P(dst_io, T_FILE)) { VALUE args[3]; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/