mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Check if closed after each yield [Bug #17661]
This commit is contained in:
parent
35c7e83bb3
commit
13939d61b4
2 changed files with 39 additions and 1 deletions
4
io.c
4
io.c
|
@ -4052,9 +4052,9 @@ rb_io_each_byte(VALUE io)
|
||||||
char *p = fptr->rbuf.ptr + fptr->rbuf.off++;
|
char *p = fptr->rbuf.ptr + fptr->rbuf.off++;
|
||||||
fptr->rbuf.len--;
|
fptr->rbuf.len--;
|
||||||
rb_yield(INT2FIX(*p & 0xff));
|
rb_yield(INT2FIX(*p & 0xff));
|
||||||
|
rb_io_check_byte_readable(fptr);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
rb_io_check_byte_readable(fptr);
|
|
||||||
READ_CHECK(fptr);
|
READ_CHECK(fptr);
|
||||||
} while (io_fillbuf(fptr) >= 0);
|
} while (io_fillbuf(fptr) >= 0);
|
||||||
return io;
|
return io;
|
||||||
|
@ -4271,6 +4271,7 @@ rb_io_each_codepoint(VALUE io)
|
||||||
fptr->cbuf.off += n;
|
fptr->cbuf.off += n;
|
||||||
fptr->cbuf.len -= n;
|
fptr->cbuf.len -= n;
|
||||||
rb_yield(UINT2NUM(c));
|
rb_yield(UINT2NUM(c));
|
||||||
|
rb_io_check_byte_readable(fptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr);
|
NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr);
|
||||||
|
@ -4308,6 +4309,7 @@ rb_io_each_codepoint(VALUE io)
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
rb_io_check_byte_readable(fptr);
|
||||||
}
|
}
|
||||||
return io;
|
return io;
|
||||||
|
|
||||||
|
|
|
@ -394,6 +394,24 @@ class TestIO < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
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
|
def test_each_codepoint
|
||||||
make_tempfile {|t|
|
make_tempfile {|t|
|
||||||
bug2959 = '[ruby-core:28650]'
|
bug2959 = '[ruby-core:28650]'
|
||||||
|
@ -405,6 +423,24 @@ class TestIO < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
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
|
def test_rubydev33072
|
||||||
t = make_tempfile
|
t = make_tempfile
|
||||||
path = t.path
|
path = t.path
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue