From 2a6ccf6c136ff7f8311b7a1a0e05081b2e872367 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 2 Feb 2012 08:52:55 +0000 Subject: * io.c (argf_next_argv): reset ARGF.next_p on ARGV.replace. r34409 breaks replacing ARGV. [ruby-dev:45160] [Bug #5952] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ io.c | 8 ++++++++ test/ruby/test_argf.rb | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 30488f2e88..0b3aee85fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Feb 2 17:51:02 2012 NARUSE, Yui + + * io.c (argf_next_argv): reset ARGF.next_p on ARGV.replace. + r34409 breaks replacing ARGV. + [ruby-dev:45160] [Bug #5952] + Thu Feb 2 16:21:01 2012 NAKAMURA Usaku * test/net/http/test_http.rb (TestNetHTTPKeepAlive#*): remove debug diff --git a/io.c b/io.c index 4bf65d9bdf..7bf5543d62 100644 --- a/io.c +++ b/io.c @@ -7306,6 +7306,14 @@ argf_next_argv(VALUE argf) } ARGF.init_p = 1; } + else { + if (NIL_P(ARGF.argv)) { + ARGF.next_p = -1; + } + else if (ARGF.next_p == -1 && RARRAY_LEN(ARGF.argv) > 0) { + ARGF.next_p = 1; + } + } if (ARGF.next_p == 1) { retry: diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index 1480ce1c41..2f1ddf5391 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -678,6 +678,16 @@ class TestArgf < Test::Unit::TestCase end end + def test_close_replace + ruby('-e', <<-SRC) do |f| + ARGF.close + ARGV.replace ['#{@t1.path}', '#{@t2.path}', '#{@t3.path}'] + puts ARGF.read + SRC + assert_equal("1\n2\n3\n4\n5\n6\n", f.read) + end + end + def test_closed ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f| 3.times do -- cgit v1.2.3