0001-change-arg-check.patch

Motohiro KOSAKI, 12/26/2010 01:34 AM

Download (2.79 KB)

View differences:

io.c
7387 7387
}
7388 7388
#endif
7389 7389

  
7390
#ifdef HAVE_POSIX_FADVISE
7391 7390
static VALUE sym_normal,   sym_sequential, sym_random,
7392 7391
             sym_willneed, sym_dontneed, sym_noreuse;
7393 7392

  
7393
#ifdef HAVE_POSIX_FADVISE
7394 7394
struct io_advise_struct {
7395 7395
    int fd;
7396 7396
    off_t offset;
......
7472 7472

  
7473 7473
#endif /* HAVE_POSIX_FADVISE */
7474 7474

  
7475
void advice_arg_check(VALUE advice)
7476
{
7477
    if (!SYMBOL_P(advice))
7478
	rb_raise(rb_eTypeError, "advice must be a Symbol");
7479

  
7480

  
7481
    if (advice != sym_normal &&
7482
	advice != sym_sequential &&
7483
	advice != sym_random &&
7484
	advice != sym_willneed &&
7485
	advice != sym_dontneed &&
7486
	advice != sym_noreuse) {
7487
	/* Unsupported advise */
7488
	rb_raise(rb_eNotImpError, "Invalid advice: :%s",
7489
		 RSTRING_PTR(rb_id2str(SYM2ID(advice))));
7490
    }
7491
}
7492

  
7475 7493
/*
7476 7494
 *  call-seq:
7477 7495
 *     ios.advise(advice, offset=0, len=0) -> nil
......
7521 7539
    rb_io_t *fptr;
7522 7540

  
7523 7541
    rb_scan_args(argc, argv, "12", &advice, &offset, &len);
7524
    if (!SYMBOL_P(advice))
7525
	rb_raise(rb_eTypeError, "advice must be a Symbol");
7542
    advice_arg_check(advice);
7526 7543

  
7527 7544
    io = GetWriteIO(io);
7528 7545
    GetOpenFile(io, fptr);
......
10521 10538
    sym_textmode = ID2SYM(rb_intern("textmode"));
10522 10539
    sym_binmode = ID2SYM(rb_intern("binmode"));
10523 10540
    sym_autoclose = ID2SYM(rb_intern("autoclose"));
10524
#ifdef HAVE_POSIX_FADVISE
10525 10541
    sym_normal = ID2SYM(rb_intern("normal"));
10526 10542
    sym_sequential = ID2SYM(rb_intern("sequential"));
10527 10543
    sym_random = ID2SYM(rb_intern("random"));
10528 10544
    sym_willneed = ID2SYM(rb_intern("willneed"));
10529 10545
    sym_dontneed = ID2SYM(rb_intern("dontneed"));
10530 10546
    sym_noreuse = ID2SYM(rb_intern("noreuse"));
10531
#endif
10532 10547
}
test/ruby/test_io.rb
1763 1763
        end
1764 1764
      end
1765 1765
    end
1766
  end
1767

  
1768
  def test_invalid_advise
1769
    feature4204 = '[ruby-dev:42887]'
1770
    t = make_tempfile
1766 1771
    %w{Normal rand glark will_need zzzzzzzzzzzz \u2609}.map(&:to_sym).each do |adv|
1767 1772
      [[0,0], [0, 20], [400, 2]].each do |offset, len|
1768 1773
        open(make_tempfile.path) do |t|
1769
          assert_equal(t.advise(adv, offset, len), nil)
1774
          assert_raise(NotImplementedError, feature4204) { t.advise(adv, offset, len) }
1770 1775
        end
1771 1776
      end
1772 1777
    end
1773
-