ruby-changes:22360
From: nobu <ko1@a...>
Date: Wed, 1 Feb 2012 06:39:28 +0900 (JST)
Subject: [ruby-changes:22360] nobu:r34409 (trunk): * io.c (argf_close): skip stdin, which should be readable again.
nobu 2012-02-01 06:39:00 +0900 (Wed, 01 Feb 2012) New Revision: 34409 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34409 Log: * io.c (argf_close): skip stdin, which should be readable again. [ruby-dev:45160] [Bug #5952] * io.c (argf_readlines): reinitialize after all read to be readable again. Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_argf.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34408) +++ ChangeLog (revision 34409) @@ -1,3 +1,11 @@ +Wed Feb 1 06:38:54 2012 Nobuyoshi Nakada <nobu@r...> + + * io.c (argf_close): skip stdin, which should be readable again. + [ruby-dev:45160] [Bug #5952] + + * io.c (argf_readlines): reinitialize after all read to be + readable again. + Tue Jan 31 21:27:43 2012 Narihiro Nakamura <authornari@g...> * configure.in (HEAP_ALIGN_LOG): HEAP_ALIGN_LOG should be page Index: io.c =================================================================== --- io.c (revision 34408) +++ io.c (revision 34409) @@ -7276,6 +7276,7 @@ static void argf_close(VALUE file) { + if (file == rb_stdin) return; if (RB_TYPE_P(file, T_FILE)) { rb_io_set_write_io(file, Qnil); } @@ -7691,6 +7692,7 @@ ARGF.lineno = lineno + RARRAY_LEN(ary); ARGF.last_lineno = ARGF.lineno; } + ARGF.init_p = 0; return ary; } Index: test/ruby/test_argf.rb =================================================================== --- test/ruby/test_argf.rb (revision 34408) +++ test/ruby/test_argf.rb (revision 34409) @@ -741,4 +741,24 @@ end assert_nil(argf.gets, bug4274) end + + def test_readlines_twice + bug5952 = '[ruby-dev:45160]' + assert_ruby_status(["-e", "2.times {STDIN.tty?; readlines}"], "", bug5952) + end + + def test_readlines_twice_tty + bug5952 = '[ruby-dev:45160]' + require 'io/console' + require 'pty' + rescue LoadError + skip $! + else + lines = nil + PTY.spawn(EnvUtil.rubybin, "-e", "2.times{STDIN.tty?; p readlines}") do |slave, master, pid| + master.write("foo\n\C-d""bar\n\C-d") + lines = slave.readlines + end + assert_equal('["bar\n"]', lines.last.chomp, bug5952) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/