Project

General

Profile

Bug #6764 ยป fix_read_buf.patch

h.shirosaki (Hiroshi Shirosaki), 09/15/2012 09:04 PM

View differences:

io.c
2281 2281
            rb_sys_fail_path(fptr->pathv);
2282 2282
        }
2283 2283
    }
2284
    rb_str_set_len(str, n);
2284
    if (RSTRING_LEN(str) != n) {
2285
	rb_str_modify(str);
2286
	rb_str_set_len(str, n);
2287
    }
2285 2288

  
2286 2289
    if (n == 0)
2287 2290
        return Qnil;
......
2602 2605
    previous_mode = set_binary_mode_with_seek_cur(fptr);
2603 2606
#endif
2604 2607
    n = io_fread(str, 0, len, fptr);
2605
    rb_str_set_len(str, n);
2608
    if (RSTRING_LEN(str) != n) {
2609
	rb_str_modify(str);
2610
	rb_str_set_len(str, n);
2611
    }
2606 2612
#if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
2607 2613
    if (previous_mode == O_TEXT) {
2608 2614
	setmode(fptr->fd, O_TEXT);
......
4390 4396
    if (n == -1) {
4391 4397
	rb_sys_fail_path(fptr->pathv);
4392 4398
    }
4393
    rb_str_set_len(str, n);
4399
    if (RSTRING_LEN(str) != n) {
4400
	rb_str_modify(str);
4401
	rb_str_set_len(str, n);
4402
    }
4394 4403
    if (n == 0 && ilen > 0) {
4395 4404
	rb_eof_error();
4396 4405
    }
test/ruby/test_io.rb
2446 2446
      assert_raise(Errno::ESPIPE, Errno::EINVAL) { w.advise(:willneed) }
2447 2447
    end
2448 2448
  end
2449

  
2450
  def test_read_buffer_not_raise_shared_string_error
2451
    bug6764 = '[ruby-core:46586]'
2452
    size = 28
2453
    t = Tempfile.new("test_io")
2454
    t.write("a" * size)
2455
    t.close
2456
    w = Tempfile.new("test_io")
2457
    assert_nothing_raised(RuntimeError, bug6764) do
2458
      File.open(t.path, "r") do |r|
2459
        buf = ''
2460
        while r.read(size, buf)
2461
          w << buf
2462
        end
2463
      end
2464
    end
2465
  ensure
2466
    t.close!
2467
    w.close!
2468
  end
2469

  
2470
  def test_sysread_buffer_not_raise_shared_string_error
2471
    bug6764 = '[ruby-core:46586]'
2472
    size = 28
2473
    t = Tempfile.new("test_io")
2474
    t.write("a" * size)
2475
    t.close
2476
    w = Tempfile.new("test_io")
2477
    assert_nothing_raised(RuntimeError, bug6764) do
2478
      File.open(t.path, "r") do |r|
2479
        buf = ''
2480
        begin
2481
          while r.sysread(size, buf)
2482
            w << buf
2483
          end
2484
        rescue EOFError
2485
        end
2486
      end
2487
    end
2488
  ensure
2489
    t.close!
2490
    w.close!
2491
  end
2492

  
2493
  def test_readpartial_buffer_not_raise_shared_string_error
2494
    bug6764 = '[ruby-core:46586]'
2495
    size = 28
2496
    t = Tempfile.new("test_io")
2497
    t.write("a" * size)
2498
    t.close
2499
    w = Tempfile.new("test_io")
2500
    assert_nothing_raised(RuntimeError, bug6764) do
2501
      File.open(t.path, "r") do |r|
2502
        buf = ''
2503
        begin
2504
          while r.readpartial(size, buf)
2505
            w << buf
2506
          end
2507
        rescue EOFError
2508
        end
2509
      end
2510
    end
2511
  ensure
2512
    t.close!
2513
    w.close!
2514
  end
2449 2515
end
2450 2516