aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--io.c2
-rw-r--r--test/ruby/test_argf.rb20
3 files changed, 30 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 1914a90836..2a74b42a33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Feb 1 06:38:54 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@gmail.com>
* configure.in (HEAP_ALIGN_LOG): HEAP_ALIGN_LOG should be page
diff --git a/io.c b/io.c
index a3a45c0b12..4bf65d9bdf 100644
--- a/io.c
+++ b/io.c
@@ -7276,6 +7276,7 @@ argf_forward(int argc, VALUE *argv, VALUE argf)
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_readlines(int argc, VALUE *argv, VALUE argf)
ARGF.lineno = lineno + RARRAY_LEN(ary);
ARGF.last_lineno = ARGF.lineno;
}
+ ARGF.init_p = 0;
return ary;
}
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index a588e07fcb..fe7603490b 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -741,4 +741,24 @@ class TestArgf < Test::Unit::TestCase
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