summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-25 00:43:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-25 00:43:06 +0000
commit898fd2ed2ad13d8c18b6a96304a8ea75ffd96b59 (patch)
treead0439504e7fe51616e9757a28e869edca248a87
parent94bdb010f6375e4df6b7f19e4e6f277d56131452 (diff)
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
-rw-r--r--ext/fiddle/function.c5
-rw-r--r--ext/stringio/stringio.c3
-rw-r--r--ext/syslog/syslog.c4
-rw-r--r--ext/win32ole/win32ole_typelib.c4
-rw-r--r--ext/win32ole/win32ole_variant.c4
-rw-r--r--ext/zlib/zlib.c4
-rw-r--r--test/win32ole/test_win32ole_variant.rb8
7 files changed, 9 insertions, 23 deletions
diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c
index e0da8b6..50a2d24 100644
--- a/ext/fiddle/function.c
+++ b/ext/fiddle/function.c
@@ -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);
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index c57b40f..9c23daf 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -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);
diff --git a/ext/syslog/syslog.c b/ext/syslog/syslog.c
index 6aa2cd8..9c41795 100644
--- a/ext/syslog/syslog.c
+++ b/ext/syslog/syslog.c
@@ -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++;
diff --git a/ext/win32ole/win32ole_typelib.c b/ext/win32ole/win32ole_typelib.c
index 5a431d8..4f2c42f 100644
--- a/ext/win32ole/win32ole_typelib.c
+++ b/ext/win32ole/win32ole_typelib.c
@@ -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);
diff --git a/ext/win32ole/win32ole_variant.c b/ext/win32ole/win32ole_variant.c
index 13a1fcf..f1fdeca 100644
--- a/ext/win32ole/win32ole_variant.c
+++ b/ext/win32ole/win32ole_variant.c
@@ -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);
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index d5a18dd..8cec7fb 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -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;
diff --git a/test/win32ole/test_win32ole_variant.rb b/test/win32ole/test_win32ole_variant.rb
index 9583a01..27ede7d 100644
--- a/test/win32ole/test_win32ole_variant.rb
+++ b/test/win32ole/test_win32ole_variant.rb
@@ -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