[前][次][番号順一覧][スレッド一覧]

ruby-changes:40194

From: nobu <ko1@a...>
Date: Sun, 25 Oct 2015 09:43:15 +0900 (JST)
Subject: [ruby-changes:40194] nobu:r52275 (trunk): use rb_check_arity [ci skip]

nobu	2015-10-25 09:43:06 +0900 (Sun, 25 Oct 2015)

  New Revision: 52275

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52275

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

  Modified files:
    trunk/ext/fiddle/function.c
    trunk/ext/stringio/stringio.c
    trunk/ext/syslog/syslog.c
    trunk/ext/win32ole/win32ole_typelib.c
    trunk/ext/win32ole/win32ole_variant.c
    trunk/ext/zlib/zlib.c
    trunk/test/win32ole/test_win32ole_variant.rb
Index: ext/syslog/syslog.c
===================================================================
--- ext/syslog/syslog.c	(revision 52274)
+++ ext/syslog/syslog.c	(revision 52275)
@@ -304,9 +304,7 @@ static VALUE mSyslog_log(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/ext/syslog/syslog.c#L304
 {
     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++;
Index: ext/zlib/zlib.c
===================================================================
--- ext/zlib/zlib.c	(revision 52274)
+++ ext/zlib/zlib.c	(revision 52275)
@@ -3097,9 +3097,7 @@ gzfile_s_open(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3097
 {
     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;
Index: ext/win32ole/win32ole_variant.c
===================================================================
--- ext/win32ole/win32ole_variant.c	(revision 52274)
+++ ext/win32ole/win32ole_variant.c	(revision 52275)
@@ -409,9 +409,7 @@ folevariant_initialize(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_variant.c#L409
     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);
 
Index: ext/win32ole/win32ole_typelib.c
===================================================================
--- ext/win32ole/win32ole_typelib.c	(revision 52274)
+++ ext/win32ole/win32ole_typelib.c	(revision 52275)
@@ -399,9 +399,7 @@ foletypelib_initialize(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_typelib.c#L399
     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);
 
Index: ext/fiddle/function.c
===================================================================
--- ext/fiddle/function.c	(revision 52274)
+++ ext/fiddle/function.c	(revision 52275)
@@ -144,9 +144,8 @@ function_call(int argc, VALUE argv[], VA https://github.com/ruby/ruby/blob/trunk/ext/fiddle/function.c#L144
     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);
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 52274)
+++ ext/stringio/stringio.c	(revision 52275)
@@ -1271,6 +1271,7 @@ strio_read(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L1271
     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 https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L1308
 	    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);
Index: test/win32ole/test_win32ole_variant.rb
===================================================================
--- test/win32ole/test_win32ole_variant.rb	(revision 52274)
+++ test/win32ole/test_win32ole_variant.rb	(revision 52275)
@@ -36,14 +36,10 @@ if defined?(WIN32OLE_VARIANT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_variant.rb#L36
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]