mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* io.c (rb_io_close_m): Don't raise when the IO object is closed.
[ruby-core:67444] [Feature #10718] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									0fce0b7ba1
								
							
						
					
					
						commit
						255955585c
					
				
					 5 changed files with 27 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,8 @@
 | 
			
		|||
Thu Jan 15 23:55:15 2015  Tanaka Akira  <akr@fsij.org>
 | 
			
		||||
 | 
			
		||||
	* io.c (rb_io_close_m): Don't raise when the IO object is closed.
 | 
			
		||||
	  [ruby-core:67444] [Feature #10718]
 | 
			
		||||
 | 
			
		||||
Thu Jan 15 21:34:57 2015  Seiei Higa  <hanachin@gmail.com>
 | 
			
		||||
 | 
			
		||||
	* proc.c (rb_obj_singleton_method): Kernel#singleton_method should
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										7
									
								
								io.c
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								io.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -4415,11 +4415,18 @@ rb_io_close(VALUE io)
 | 
			
		|||
 *
 | 
			
		||||
 *  If <em>ios</em> is opened by <code>IO.popen</code>,
 | 
			
		||||
 *  <code>close</code> sets <code>$?</code>.
 | 
			
		||||
 *
 | 
			
		||||
 *  Calling this method on closed IO object is just ignored since Ruby 2.3.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
rb_io_close_m(VALUE io)
 | 
			
		||||
{
 | 
			
		||||
    rb_io_t *fptr = RFILE(io)->fptr;
 | 
			
		||||
    rb_io_check_initialized(fptr);
 | 
			
		||||
    if (fptr->fd < 0) {
 | 
			
		||||
        return Qnil;
 | 
			
		||||
    }
 | 
			
		||||
    rb_io_check_closed(RFILE(io)->fptr);
 | 
			
		||||
    rb_io_close(io);
 | 
			
		||||
    return Qnil;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3159,4 +3159,17 @@ End
 | 
			
		|||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_close_twice
 | 
			
		||||
    open(__FILE__) {|f|
 | 
			
		||||
      assert_equal(nil, f.close)
 | 
			
		||||
      assert_equal(nil, f.close)
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_close_uninitialized
 | 
			
		||||
    io = IO.allocate
 | 
			
		||||
    assert_raise(IOError) { io.close } 
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ class TestSocket_BasicSocket < Test::Unit::TestCase
 | 
			
		|||
    sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
 | 
			
		||||
    yield sock
 | 
			
		||||
  ensure
 | 
			
		||||
    assert_raise(IOError) {sock.close}
 | 
			
		||||
    assert(sock.closed?)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_getsockopt
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -929,7 +929,7 @@ if defined? Zlib
 | 
			
		|||
        f = open(t.path)
 | 
			
		||||
        f.binmode
 | 
			
		||||
        assert_equal("foo", Zlib::GzipReader.wrap(f) {|gz| gz.read })
 | 
			
		||||
        assert_raise(IOError) { f.close }
 | 
			
		||||
        assert(f.closed?)
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue