diff options
| author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-09 20:12:02 +0000 |
|---|---|---|
| committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-09 20:12:02 +0000 |
| commit | 36b3d5577ca9c9e32fa690149d73d557af996422 (patch) | |
| tree | 8aa46568cdf61990c1fec5aaba1ec86dd11de8bc | |
| parent | 0234bcfd19aa0a7b4152809c13554144b7322f41 (diff) | |
merge revision(s) 34409,34412,34417:
* 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.
* 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/branches/ruby_1_9_3@34528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 14 | ||||
| -rw-r--r-- | io.c | 10 | ||||
| -rw-r--r-- | test/ruby/test_argf.rb | 15 | ||||
| -rw-r--r-- | version.h | 2 |
4 files changed, 40 insertions, 1 deletions
@@ -1,3 +1,17 @@ +Fri Feb 10 05:11:43 2012 NARUSE, Yui <naruse@ruby-lang.org> + + * io.c (argf_next_argv): reset ARGF.next_p on ARGV.replace. + r34409 breaks replacing ARGV. + [ruby-dev:45160] [Bug #5952] + +Fri Feb 10 05:11:43 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. + Fri Feb 9 01:36:19 2012 Martin Bosslet <Martin.Bosslet@googlemail.com> * backport r34482 from trunk @@ -6852,6 +6852,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); } @@ -6881,6 +6882,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: @@ -7262,6 +7271,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 a033a74d32..bf6996f0de 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -685,6 +685,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 @@ -748,4 +758,9 @@ 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 end @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 76 +#define RUBY_PATCHLEVEL 77 #define RUBY_RELEASE_DATE "2012-02-10" #define RUBY_RELEASE_YEAR 2012 |
