1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

use rb_check_arity [ci skip]

* ext: use rb_check_arity and rb_error_arity to raise
  ArgumentError.  [Feature #9025]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-10-25 00:43:06 +00:00
parent 94bdb010f6
commit 898fd2ed2a
7 changed files with 9 additions and 23 deletions

View file

@ -144,9 +144,8 @@ function_call(int argc, VALUE argv[], VALUE self)
cPointer = rb_const_get(mFiddle, rb_intern("Pointer"));
Check_Max_Args("number of arguments", argc);
if(argc != RARRAY_LENINT(types)) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
argc, RARRAY_LENINT(types));
if (argc != (i = RARRAY_LENINT(types))) {
rb_error_arity(argc, i, i);
}
TypedData_Get_Struct(self, ffi_cif, &function_data_type, cif);

View file

@ -1271,6 +1271,7 @@ strio_read(int argc, VALUE *argv, VALUE self)
long len;
int binary = 0;
rb_check_arity(argc, 0, 2);
switch (argc) {
case 2:
str = argv[1];
@ -1307,8 +1308,6 @@ strio_read(int argc, VALUE *argv, VALUE self)
len -= ptr->pos;
}
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
if (NIL_P(str)) {
str = strio_substr(ptr, ptr->pos, len);

View file

@ -304,9 +304,7 @@ static VALUE mSyslog_log(int argc, VALUE *argv, VALUE self)
{
VALUE pri;
if (argc < 2) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);
}
rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
argc--;
pri = *argv++;

View file

@ -399,9 +399,7 @@ foletypelib_initialize(VALUE self, VALUE args)
HRESULT hr = S_OK;
len = RARRAY_LEN(args);
if (len < 1 || len > 3) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
}
rb_check_arity(len, 1, 3);
typelib = rb_ary_entry(args, 0);

View file

@ -409,9 +409,7 @@ folevariant_initialize(VALUE self, VALUE args)
struct olevariantdata *pvar;
len = RARRAY_LEN(args);
if (len < 1 || len > 3) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
}
rb_check_arity(len, 1, 3);
VariantInit(&var);
val = rb_ary_entry(args, 0);

View file

@ -3097,9 +3097,7 @@ gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
{
VALUE io, filename;
if (argc < 1) {
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
}
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
filename = argv[0];
io = rb_file_open_str(filename, mode);
argv[0] = io;

View file

@ -36,14 +36,10 @@ if defined?(WIN32OLE_VARIANT)
end
def test_s_new_no_argument
ex = nil
begin
pat = /wrong number of arguments \(.*\b0\b.* 1\.\.3\)/
assert_raise_with_message(ArgumentError, pat) do
WIN32OLE_VARIANT.new
rescue ArgumentError
ex = $!
end
assert_instance_of(ArgumentError, ex)
assert_equal("wrong number of arguments (0 for 1..3)", ex.message);
end
def test_s_new_one_argument