summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--io.c18
-rw-r--r--test/ruby/test_argf.rb18
3 files changed, 37 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f441041bd..35d20289d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Nov 14 12:05:24 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (argf_readlines): forward to current_file for arguments
+ check. http://twitter.com/nagachika/status/3634254856589312
+
Sun Nov 14 08:48:06 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/setup.mak (-basic-vars-, -runtime-): suppress trailing
diff --git a/io.c b/io.c
index b668688821..174a4ef189 100644
--- a/io.c
+++ b/io.c
@@ -7172,13 +7172,23 @@ rb_f_readlines(int argc, VALUE *argv, VALUE recv)
static VALUE
argf_readlines(int argc, VALUE *argv, VALUE argf)
{
- VALUE line, ary;
+ int lineno = ARGF.lineno;
+ VALUE lines, ary;
ary = rb_ary_new();
- while (!NIL_P(line = argf_getline(argc, argv, argf))) {
- rb_ary_push(ary, line);
+ while (next_argv()) {
+ if (ARGF_GENERIC_INPUT_P()) {
+ lines = rb_funcall3(ARGF.current_file, rb_intern("readlines"), argc, argv);
+ }
+ else {
+ lines = rb_io_readlines(argc, argv, ARGF.current_file);
+ argf_close(ARGF.current_file);
+ }
+ ARGF.next_p = 1;
+ rb_ary_concat(ary, lines);
+ ARGF.lineno = lineno + RARRAY_LEN(ary);
+ ARGF.last_lineno = ARGF.lineno;
}
-
return ary;
}
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index ffd5096789..992c37b261 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -694,4 +694,22 @@ class TestArgf < Test::Unit::TestCase
assert_equal([@t1.path, @t2.path, @t3.path].inspect, f.gets.chomp)
end
end
+
+ def test_readlines_limit_0
+ bug4024 = '[ruby-dev:42538]'
+ t = make_tempfile
+ argf = ARGF.class.new(t.path)
+ assert_raise(ArgumentError, bug4024) do
+ argf.readlines(0)
+ end
+ end
+
+ def test_each_line_limit_0
+ bug4024 = '[ruby-dev:42538]'
+ t = make_tempfile
+ argf = ARGF.class.new(t.path)
+ assert_raise(ArgumentError, bug4024) do
+ argf.each_line(0).next
+ end
+ end
end