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:
parent
94bdb010f6
commit
898fd2ed2a
7 changed files with 9 additions and 23 deletions
|
@ -144,9 +144,8 @@ function_call(int argc, VALUE argv[], VALUE self)
|
||||||
cPointer = rb_const_get(mFiddle, rb_intern("Pointer"));
|
cPointer = rb_const_get(mFiddle, rb_intern("Pointer"));
|
||||||
|
|
||||||
Check_Max_Args("number of arguments", argc);
|
Check_Max_Args("number of arguments", argc);
|
||||||
if(argc != RARRAY_LENINT(types)) {
|
if (argc != (i = RARRAY_LENINT(types))) {
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
|
rb_error_arity(argc, i, i);
|
||||||
argc, RARRAY_LENINT(types));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedData_Get_Struct(self, ffi_cif, &function_data_type, cif);
|
TypedData_Get_Struct(self, ffi_cif, &function_data_type, cif);
|
||||||
|
|
|
@ -1271,6 +1271,7 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
||||||
long len;
|
long len;
|
||||||
int binary = 0;
|
int binary = 0;
|
||||||
|
|
||||||
|
rb_check_arity(argc, 0, 2);
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 2:
|
case 2:
|
||||||
str = argv[1];
|
str = argv[1];
|
||||||
|
@ -1307,8 +1308,6 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
||||||
len -= ptr->pos;
|
len -= ptr->pos;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
|
|
||||||
}
|
}
|
||||||
if (NIL_P(str)) {
|
if (NIL_P(str)) {
|
||||||
str = strio_substr(ptr, ptr->pos, len);
|
str = strio_substr(ptr, ptr->pos, len);
|
||||||
|
|
|
@ -304,9 +304,7 @@ static VALUE mSyslog_log(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
VALUE pri;
|
VALUE pri;
|
||||||
|
|
||||||
if (argc < 2) {
|
rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);
|
|
||||||
}
|
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
pri = *argv++;
|
pri = *argv++;
|
||||||
|
|
|
@ -399,9 +399,7 @@ foletypelib_initialize(VALUE self, VALUE args)
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
|
|
||||||
len = RARRAY_LEN(args);
|
len = RARRAY_LEN(args);
|
||||||
if (len < 1 || len > 3) {
|
rb_check_arity(len, 1, 3);
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
|
|
||||||
}
|
|
||||||
|
|
||||||
typelib = rb_ary_entry(args, 0);
|
typelib = rb_ary_entry(args, 0);
|
||||||
|
|
||||||
|
|
|
@ -409,9 +409,7 @@ folevariant_initialize(VALUE self, VALUE args)
|
||||||
struct olevariantdata *pvar;
|
struct olevariantdata *pvar;
|
||||||
|
|
||||||
len = RARRAY_LEN(args);
|
len = RARRAY_LEN(args);
|
||||||
if (len < 1 || len > 3) {
|
rb_check_arity(len, 1, 3);
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
|
|
||||||
}
|
|
||||||
VariantInit(&var);
|
VariantInit(&var);
|
||||||
val = rb_ary_entry(args, 0);
|
val = rb_ary_entry(args, 0);
|
||||||
|
|
||||||
|
|
|
@ -3097,9 +3097,7 @@ gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
|
||||||
{
|
{
|
||||||
VALUE io, filename;
|
VALUE io, filename;
|
||||||
|
|
||||||
if (argc < 1) {
|
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
|
|
||||||
}
|
|
||||||
filename = argv[0];
|
filename = argv[0];
|
||||||
io = rb_file_open_str(filename, mode);
|
io = rb_file_open_str(filename, mode);
|
||||||
argv[0] = io;
|
argv[0] = io;
|
||||||
|
|
|
@ -36,14 +36,10 @@ if defined?(WIN32OLE_VARIANT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_s_new_no_argument
|
def test_s_new_no_argument
|
||||||
ex = nil
|
pat = /wrong number of arguments \(.*\b0\b.* 1\.\.3\)/
|
||||||
begin
|
assert_raise_with_message(ArgumentError, pat) do
|
||||||
WIN32OLE_VARIANT.new
|
WIN32OLE_VARIANT.new
|
||||||
rescue ArgumentError
|
|
||||||
ex = $!
|
|
||||||
end
|
end
|
||||||
assert_instance_of(ArgumentError, ex)
|
|
||||||
assert_equal("wrong number of arguments (0 for 1..3)", ex.message);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_s_new_one_argument
|
def test_s_new_one_argument
|
||||||
|
|
Loading…
Add table
Reference in a new issue