summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2021-09-18 16:07:30 +0900
committernagachika <nagachika@ruby-lang.org>2021-09-18 16:07:30 +0900
commite6e25b794d8db52e1df85a02f28846ad7eb82d49 (patch)
tree35ed9d6c0fea1d52c123e7e38c7af71b3d6ac0da
parent650af7d29d98de6a3c2631e31edc6fbe435ece89 (diff)
merge revision(s) 13939d61b4b69bd109c5f41303c79868d639fa44: [Backport #17661]
Check if closed after each yield [Bug #17661] --- io.c | 4 +++- test/ruby/test_io.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-)
-rw-r--r--io.c4
-rw-r--r--test/ruby/test_io.rb36
-rw-r--r--version.h4
3 files changed, 41 insertions, 3 deletions
diff --git a/io.c b/io.c
index bc31c7bffd..521b0b0e9a 100644
--- a/io.c
+++ b/io.c
@@ -3994,9 +3994,9 @@ rb_io_each_byte(VALUE io)
char *p = fptr->rbuf.ptr + fptr->rbuf.off++;
fptr->rbuf.len--;
rb_yield(INT2FIX(*p & 0xff));
+ rb_io_check_byte_readable(fptr);
errno = 0;
}
- rb_io_check_byte_readable(fptr);
READ_CHECK(fptr);
} while (io_fillbuf(fptr) >= 0);
return io;
@@ -4215,6 +4215,7 @@ rb_io_each_codepoint(VALUE io)
fptr->cbuf.off += n;
fptr->cbuf.len -= n;
rb_yield(UINT2NUM(c));
+ rb_io_check_byte_readable(fptr);
}
}
NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr);
@@ -4252,6 +4253,7 @@ rb_io_each_codepoint(VALUE io)
else {
continue;
}
+ rb_io_check_byte_readable(fptr);
}
return io;
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 9f9318eaf7..58a739be22 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -394,6 +394,24 @@ class TestIO < Test::Unit::TestCase
}
end
+ def test_each_byte_closed
+ pipe(proc do |w|
+ w << "abc def"
+ w.close
+ end, proc do |r|
+ assert_raise(IOError) do
+ r.each_byte {|byte| r.close if byte == 32 }
+ end
+ end)
+ make_tempfile {|t|
+ File.open(t, 'rt') {|f|
+ assert_raise(IOError) do
+ f.each_byte {|c| f.close if c == 10}
+ end
+ }
+ }
+ end
+
def test_each_codepoint
make_tempfile {|t|
bug2959 = '[ruby-core:28650]'
@@ -405,6 +423,24 @@ class TestIO < Test::Unit::TestCase
}
end
+ def test_each_codepoint_closed
+ pipe(proc do |w|
+ w.print("abc def")
+ w.close
+ end, proc do |r|
+ assert_raise(IOError) do
+ r.each_codepoint {|c| r.close if c == 32}
+ end
+ end)
+ make_tempfile {|t|
+ File.open(t, 'rt') {|f|
+ assert_raise(IOError) do
+ f.each_codepoint {|c| f.close if c == 10}
+ end
+ }
+ }
+ end
+
def test_rubydev33072
t = make_tempfile
path = t.path
diff --git a/version.h b/version.h
index 9380309c41..d619bf8f50 100644
--- a/version.h
+++ b/version.h
@@ -12,11 +12,11 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 3
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 133
+#define RUBY_PATCHLEVEL 134
#define RUBY_RELEASE_YEAR 2021
#define RUBY_RELEASE_MONTH 9
-#define RUBY_RELEASE_DAY 11
+#define RUBY_RELEASE_DAY 18
#include "ruby/version.h"