ruby-changes:71307
From: Burdette <ko1@a...>
Date: Wed, 2 Mar 2022 03:08:09 +0900 (JST)
Subject: [ruby-changes:71307] 4bdb4a1873 (master): Close files in examples in io.c (#5615)
https://git.ruby-lang.org/ruby.git/commit/?id=4bdb4a1873 From 4bdb4a1873bea9768bcf1bff8d7bffd80fdabb44 Mon Sep 17 00:00:00 2001 From: Burdette Lamar <BurdetteLamar@Y...> Date: Tue, 1 Mar 2022 12:07:54 -0600 Subject: Close files in examples in io.c (#5615) --- io.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/io.c b/io.c index 19becbd181..f4c7476314 100644 --- a/io.c +++ b/io.c @@ -2196,6 +2196,7 @@ rb_io_flush(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2196 * f.tell # => 0 * f.gets # => "First line\n" * f.tell # => 12 + * f.close * * Related: IO#pos=, IO#seek. * @@ -2267,6 +2268,7 @@ interpret_seek_whence(VALUE vwhence) https://github.com/ruby/ruby/blob/trunk/io.c#L2268 * f.tell # => 20 * f.seek(-10, :CUR) # => 0 * f.tell # => 10 + * f.close * * - +:END+ or <tt>IO::SEEK_END</tt>: * Repositions the stream to its end plus the given +offset+: @@ -2279,6 +2281,7 @@ interpret_seek_whence(VALUE vwhence) https://github.com/ruby/ruby/blob/trunk/io.c#L2281 * f.tell # => 32 * f.seek(-40, :END) # => 0 * f.tell # => 12 + * f.close * * - +:SET+ or <tt>IO:SEEK_SET</tt>: * Repositions the stream to the given +offset+: @@ -2289,6 +2292,7 @@ interpret_seek_whence(VALUE vwhence) https://github.com/ruby/ruby/blob/trunk/io.c#L2292 * f.tell # => 20 * f.seek(40, :SET) # => 0 * f.tell # => 40 + * f.close * * Related: IO#pos=, IO#tell. * @@ -2318,6 +2322,7 @@ rb_io_seek_m(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2322 * f.tell # => 0 * f.pos = 20 # => 20 * f.tell # => 20 + * f.close * * Related: IO#seek, IO#tell. * @@ -2357,6 +2362,7 @@ static void clear_readconv(rb_io_t *fptr); https://github.com/ruby/ruby/blob/trunk/io.c#L2362 * f.rewind # => 0 * f.tell # => 0 * f.lineno # => 0 + * f.close * * Note that this method cannot be used with streams such as pipes, ttys, and sockets. * @@ -2441,6 +2447,7 @@ io_fillbuf(rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L2447 * f.eof # => false * f.seek(0, :END) # => 0 * f.eof # => true + * f.close * * Raises an exception unless the stream is opened for reading; * see {Mode}[rdoc-ref:IO@Mode]. @@ -2498,6 +2505,7 @@ rb_io_eof(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2505 * f.sync # => false * f.sync = true * f.sync # => true + * f.close * */ @@ -2532,6 +2540,7 @@ rb_io_sync(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2540 * f.sync # => false * f.sync = true * f.sync # => true + * f.close * * Related: IO#fsync. * @@ -2651,6 +2660,7 @@ rb_io_fdatasync(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2660 * $stdout.fileno # => 1 * $stderr.fileno # => 2 * File.open('t.txt').fileno # => 10 + * f.close * * IO#to_i is an alias for IO#fileno. * @@ -2722,6 +2732,7 @@ rb_io_pid(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2732 * * f = File.open('t.txt') * f.inspect # => "#<File:t.txt>" + * f.close * */ @@ -3258,6 +3269,7 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int no_exception, int nonblock) https://github.com/ruby/ruby/blob/trunk/io.c#L3269 * f.readpartial(20) # => "ine\n\nFourth line\n" * f.readpartial(20) # => "Fifth line\n" * f.readpartial(20) # Raises EOFError. + * f.close * * With both argument +maxlen+ and string argument +out_string+ given, * returns modified +out_string+: @@ -3267,6 +3279,7 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int no_exception, int nonblock) https://github.com/ruby/ruby/blob/trunk/io.c#L3279 * f.readpartial(20, s) # => "First line\nSecond l" * s = 'bar' * f.readpartial(0, s) # => "" + * f.close * * This method is useful for a stream such as a pipe, a socket, or a tty. * It blocks only when no data is immediately available. @@ -3469,6 +3482,7 @@ io_write_nonblock(rb_execution_context_t *ec, VALUE io, VALUE str, VALUE ex) https://github.com/ruby/ruby/blob/trunk/io.c#L3482 * f.read(30) # => "First line\r\nSecond line\r\n\r\nFou" * f.read(30) # => "rth line\r\nFifth line\r\n" * f.read(30) # => nil + * f.close * * If +maxlen+ is zero, returns an empty string. * @@ -3491,6 +3505,7 @@ io_write_nonblock(rb_execution_context_t *ec, VALUE io, VALUE str, VALUE ex) https://github.com/ruby/ruby/blob/trunk/io.c#L3505 * s = 'bat' * f.read(30, s) # => nil * s # => "" + * f.close * * Note that this method behaves like the fread() function in C. * This means it retries to invoke read(2) system calls to read data @@ -4005,6 +4020,7 @@ rb_io_gets_internal(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4020 * f.gets # => "Fourth line\n" * f.gets # => "Fifth line\n" * f.gets # => nil + * f.close * * With only string argument +sep+ given, * returns the next line as determined by line separator +sep+, @@ -4016,6 +4032,7 @@ rb_io_gets_internal(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4032 * f.gets('li') # => "ine\nSecond li" * f.gets('lin') # => "ne\n\nFourth lin" * f.gets # => "e\n" + * f.close * * The two special values for +sep+ are honored: * @@ -4025,6 +4042,7 @@ rb_io_gets_internal(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4042 * f.rewind * # Get paragraph (up to two line separators). * f.gets('') # => "First line\nSecond line\n\n" + * f.close * * With only integer argument +limit+ given, * limits the number of bytes in the line; @@ -4053,6 +4071,7 @@ rb_io_gets_internal(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4071 * f.gets(chomp: true) # => "Fourth line" * f.gets(chomp: true) # => "Fifth line" * f.gets(chomp: true) # => nil + * f.close * */ @@ -4146,6 +4165,7 @@ static VALUE io_readlines(const struct getline_arg *arg, VALUE io); https://github.com/ruby/ruby/blob/trunk/io.c#L4165 * f.readlines * # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"] * f.readlines # => [] + * f.close * * With only string argument +sep+ given, * returns lines as determined by line separator +sep+, @@ -4155,6 +4175,7 @@ static VALUE io_readlines(const struct getline_arg *arg, VALUE io); https://github.com/ruby/ruby/blob/trunk/io.c#L4175 * f = File.new('t.txt') * f.readlines('li') * # => ["First li", "ne\nSecond li", "ne\n\nFourth li", "ne\nFifth li", "ne\n"] + * f.close * * The two special values for +sep+ are honored: * @@ -4166,6 +4187,7 @@ static VALUE io_readlines(const struct getline_arg *arg, VALUE io); https://github.com/ruby/ruby/blob/trunk/io.c#L4187 * f.rewind * f.readlines('') * # => ["First line\nSecond line\n\n", "Fourth line\nFifth line\n"] + * f.close * * With only integer argument +limit+ given, * limits the number of bytes in each line; @@ -4174,6 +4196,7 @@ static VALUE io_readlines(const struct getline_arg *arg, VALUE io); https://github.com/ruby/ruby/blob/trunk/io.c#L4196 * f = File.new('t.txt') * f.readlines(8) * # => ["First li", "ne\n", "Second l", "ine\n", "\n", "Fourth l", "ine\n", "Fifth li", "ne\n"] + * f.close * * With arguments +sep+ and +limit+ given, * combines the two behaviors: @@ -4187,6 +4210,7 @@ static VALUE io_readlines(const struct getline_arg *arg, VALUE io); https://github.com/ruby/ruby/blob/trunk/io.c#L4210 * f = File.new('t.txt') * f.readlines(chomp: true) * # => ["First line", "Second line", "", "Fourth line", "Fifth line"] + * f.close * */ @@ -4231,6 +4255,7 @@ io_readlines(const struct getline_arg *arg, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4255 * f = File.new('t.txt') * f.each_line {|line| p line } * f.each_line {|line| fail 'Cannot happen' } + * f.close * * Output: * @@ -4246,6 +4271,7 @@ io_readlines(const struct getline_arg *arg, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4271 * * f = File.new('t.txt') * f.each_line('li') {|line| p line } + * f.close * * Output: * @@ -4260,6 +4286,7 @@ io_readlines(const struct getline_arg *arg, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4286 * f = File.new('t.txt') * # Get all into one string. * f.each_line(nil) {|line| p line } + * f.close * * Output: * @@ -4280,6 +4307,7 @@ io_readlines(const struct getline_arg *arg, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4307 * * f = File.new('t.txt') * f.each_line(8) {|line| p line } + * f.close * * Output: * @@ -4304,6 +4332,7 @@ io_readlines(const struct getline_arg *arg, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4332 * * f = File.new('t.txt') * f.each_line(chomp: true) {|line| p line } + * f.close * * Output: * @@ -4346,6 +4375,7 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4375 * a = [] * f.each_byte {|b| a << b } * a # => [209, 130, 208, 181, 209, 129, 209, 130] + * f.close * * Returns an Enumerator if no block is given. * @@ -4492,6 +4522,7 @@ io_getc(rb_io_t *fptr, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/io.c#L4522 * a = [] * f.each_char {|c| a << c.ord } * a # => [1090, 1077, 1089, 1090] + * f.close * * Returns an Enumerator if no block is given. * @@ -4529,6 +4560,7 @@ rb_io_each_char(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4560 * a = [] * f.each_codepoint {|c| a << c } * a # => [1090, 1077, 1089, 1090] + * f.close * * Returns an Enumerator if no block i (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/