ruby-changes:66613
From: Nobuyoshi <ko1@a...>
Date: Sun, 27 Jun 2021 11:38:32 +0900 (JST)
Subject: [ruby-changes:66613] 13939d61b4 (master): Check if closed after each yield [Bug #17661]
https://git.ruby-lang.org/ruby.git/commit/?id=13939d61b4 From 13939d61b4b69bd109c5f41303c79868d639fa44 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 27 Jun 2021 09:42:01 +0900 Subject: Check if closed after each yield [Bug #17661] --- io.c | 4 +++- test/ruby/test_io.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/io.c b/io.c index 7f7d6e3..fa07f53 100644 --- a/io.c +++ b/io.c @@ -4052,9 +4052,9 @@ rb_io_each_byte(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4052 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; @@ -4271,6 +4271,7 @@ rb_io_each_codepoint(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4271 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); @@ -4308,6 +4309,7 @@ rb_io_each_codepoint(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4309 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 14592e4..7acedb6 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -394,6 +394,24 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L394 } 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L423 } 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/