mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (advice_arg_check): Change argument check.
Now, an unsupported advice makes NotImplementedError. [ruby-dev:42887] [Ruby 1.9-Feature#4204] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6bd4afaab8
commit
085e40d45b
3 changed files with 31 additions and 6 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Sun Dec 26 02:31:58 2010 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* io.c (advice_arg_check): Change argument check.
|
||||||
|
Now, an unsupported advice makes NotImplementedError.
|
||||||
|
[ruby-dev:42887] [Ruby 1.9-Feature#4204]
|
||||||
|
|
||||||
Sun Dec 26 03:00:53 2010 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Sun Dec 26 03:00:53 2010 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* ext/socket/extconf.rb: Fix build error which was introduced r30372.
|
* ext/socket/extconf.rb: Fix build error which was introduced r30372.
|
||||||
|
|
24
io.c
24
io.c
|
@ -7396,10 +7396,10 @@ select_end(VALUE arg)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_POSIX_FADVISE
|
|
||||||
static VALUE sym_normal, sym_sequential, sym_random,
|
static VALUE sym_normal, sym_sequential, sym_random,
|
||||||
sym_willneed, sym_dontneed, sym_noreuse;
|
sym_willneed, sym_dontneed, sym_noreuse;
|
||||||
|
|
||||||
|
#ifdef HAVE_POSIX_FADVISE
|
||||||
struct io_advise_struct {
|
struct io_advise_struct {
|
||||||
int fd;
|
int fd;
|
||||||
off_t offset;
|
off_t offset;
|
||||||
|
@ -7481,6 +7481,23 @@ do_io_advise(rb_io_t *fptr, VALUE advice, off_t offset, off_t len)
|
||||||
|
|
||||||
#endif /* HAVE_POSIX_FADVISE */
|
#endif /* HAVE_POSIX_FADVISE */
|
||||||
|
|
||||||
|
static void
|
||||||
|
advice_arg_check(VALUE advice)
|
||||||
|
{
|
||||||
|
if (!SYMBOL_P(advice))
|
||||||
|
rb_raise(rb_eTypeError, "advice must be a Symbol");
|
||||||
|
|
||||||
|
if (advice != sym_normal &&
|
||||||
|
advice != sym_sequential &&
|
||||||
|
advice != sym_random &&
|
||||||
|
advice != sym_willneed &&
|
||||||
|
advice != sym_dontneed &&
|
||||||
|
advice != sym_noreuse) {
|
||||||
|
rb_raise(rb_eNotImpError, "Unsupported advice: :%s",
|
||||||
|
RSTRING_PTR(rb_id2str(SYM2ID(advice))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* ios.advise(advice, offset=0, len=0) -> nil
|
* ios.advise(advice, offset=0, len=0) -> nil
|
||||||
|
@ -7530,8 +7547,7 @@ rb_io_advise(int argc, VALUE *argv, VALUE io)
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "12", &advice, &offset, &len);
|
rb_scan_args(argc, argv, "12", &advice, &offset, &len);
|
||||||
if (!SYMBOL_P(advice))
|
advice_arg_check(advice);
|
||||||
rb_raise(rb_eTypeError, "advice must be a Symbol");
|
|
||||||
|
|
||||||
io = GetWriteIO(io);
|
io = GetWriteIO(io);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
|
@ -10530,12 +10546,10 @@ Init_IO(void)
|
||||||
sym_textmode = ID2SYM(rb_intern("textmode"));
|
sym_textmode = ID2SYM(rb_intern("textmode"));
|
||||||
sym_binmode = ID2SYM(rb_intern("binmode"));
|
sym_binmode = ID2SYM(rb_intern("binmode"));
|
||||||
sym_autoclose = ID2SYM(rb_intern("autoclose"));
|
sym_autoclose = ID2SYM(rb_intern("autoclose"));
|
||||||
#ifdef HAVE_POSIX_FADVISE
|
|
||||||
sym_normal = ID2SYM(rb_intern("normal"));
|
sym_normal = ID2SYM(rb_intern("normal"));
|
||||||
sym_sequential = ID2SYM(rb_intern("sequential"));
|
sym_sequential = ID2SYM(rb_intern("sequential"));
|
||||||
sym_random = ID2SYM(rb_intern("random"));
|
sym_random = ID2SYM(rb_intern("random"));
|
||||||
sym_willneed = ID2SYM(rb_intern("willneed"));
|
sym_willneed = ID2SYM(rb_intern("willneed"));
|
||||||
sym_dontneed = ID2SYM(rb_intern("dontneed"));
|
sym_dontneed = ID2SYM(rb_intern("dontneed"));
|
||||||
sym_noreuse = ID2SYM(rb_intern("noreuse"));
|
sym_noreuse = ID2SYM(rb_intern("noreuse"));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1763,10 +1763,15 @@ End
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_advise
|
||||||
|
feature4204 = '[ruby-dev:42887]'
|
||||||
|
t = make_tempfile
|
||||||
%w{Normal rand glark will_need zzzzzzzzzzzz \u2609}.map(&:to_sym).each do |adv|
|
%w{Normal rand glark will_need zzzzzzzzzzzz \u2609}.map(&:to_sym).each do |adv|
|
||||||
[[0,0], [0, 20], [400, 2]].each do |offset, len|
|
[[0,0], [0, 20], [400, 2]].each do |offset, len|
|
||||||
open(make_tempfile.path) do |t|
|
open(make_tempfile.path) do |t|
|
||||||
assert_equal(t.advise(adv, offset, len), nil)
|
assert_raise(NotImplementedError, feature4204) { t.advise(adv, offset, len) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue