fix_pos_with_readline.patch

Hiroshi Shirosaki, 05/07/2012 09:19 PM

Download (1.28 KB)

View differences:

io.c
457 457
    /* add extra offset for removed '\r' in rbuf */
458 458
    extra_max = (long)(pos - fptr->rbuf.len);
459 459
    p = fptr->rbuf.ptr + fptr->rbuf.off;
460

  
461
    /* if the end of rbuf is '\r', rbuf doesn't have '\r' within rbuf.len */
462
    if (*(fptr->rbuf.ptr + fptr->rbuf.capa - 1) == '\r') {
463
	newlines++;
464
    }
465

  
460 466
    for (i = 0; i < fptr->rbuf.len; i++) {
461 467
	if (*p == '\n') newlines++;
462 468
	if (extra_max == newlines) break;
test/ruby/test_io_m17n.rb
2432 2432
    }
2433 2433
  end if /mswin|mingw/ =~ RUBY_PLATFORM
2434 2434

  
2435
  def test_pos_with_buffer_end_cr
2436
    bug6401 = '[ruby-core:44874]'
2437
    with_tmpdir {
2438
      # Read buffer size is 8191. This generates '\r' at 8191.
2439
      lines = ["X" * 8187, "X"]
2440
      generate_file("tmp", lines.join("\r\n") + "\r\n")
2441

  
2442
      open("tmp", "r") do |f|
2443
        lines.each do |line|
2444
          f.pos
2445
          assert_equal(line, f.readline.chomp, bug6401)
2446
        end
2447
      end
2448
    }
2449
  end if /mswin|mingw/ =~ RUBY_PLATFORM
2450

  
2435 2451
  def test_read_crlf_and_eof
2436 2452
    bug6271 = '[ruby-core:44189]'
2437 2453
    with_tmpdir {