Project

General

Profile

Feature #10718 ยป io-close.patch

akr (Akira Tanaka), 01/09/2015 01:44 AM

View differences:

io.c (working copy)
4415 4415
 *
4416 4416
 *  If <em>ios</em> is opened by <code>IO.popen</code>,
4417 4417
 *  <code>close</code> sets <code>$?</code>.
4418
 *
4419
 *  Calling this method on closed IO object is just ignored since Ruby 2.3.
4418 4420
 */
4419 4421

  
4420 4422
static VALUE
4421 4423
rb_io_close_m(VALUE io)
4422 4424
{
4425
    rb_io_t *fptr = RFILE(io)->fptr;
4426
    rb_io_check_initialized(fptr);
4427
    if (fptr->fd < 0) {
4428
        return Qnil;
4429
    }
4423 4430
    rb_io_check_closed(RFILE(io)->fptr);
4424 4431
    rb_io_close(io);
4425 4432
    return Qnil;
test/ruby/test_io.rb (working copy)
3159 3159
      end
3160 3160
    end
3161 3161
  end
3162

  
3163
  def test_close_twice
3164
    open(__FILE__) {|f|
3165
      assert_equal(nil, f.close)
3166
      assert_equal(nil, f.close)
3167
    }
3168
  end
3169

  
3170
  def test_close_uninitialized
3171
    io = IO.allocate
3172
    assert_raise(IOError) { io.close } 
3173
  end
3174

  
3162 3175
end
test/socket/test_basicsocket.rb (working copy)
9 9
    sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
10 10
    yield sock
11 11
  ensure
12
    assert_raise(IOError) {sock.close}
12
    assert(sock.closed?)
13 13
  end
14 14

  
15 15
  def test_getsockopt
test/zlib/test_zlib.rb (working copy)
929 929
        f = open(t.path)
930 930
        f.binmode
931 931
        assert_equal("foo", Zlib::GzipReader.wrap(f) {|gz| gz.read })
932
        assert_raise(IOError) { f.close }
932
        assert(f.closed?)
933 933
      }
934 934
    end
935 935