summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--io.c10
-rw-r--r--test/ruby/test_argf.rb15
-rw-r--r--version.h2
4 files changed, 40 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4d51f894a1..52db45ac58 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/io.c b/io.c
index cc9e50e685..1c4b54ab70 100644
--- a/io.c
+++ b/io.c
@@ -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
diff --git a/version.h b/version.h
index b646ea1d26..8ff198d179 100644
--- a/version.h
+++ b/version.h
@@ -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