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

ruby-changes:73828

From: Nobuyoshi <ko1@a...>
Date: Sat, 1 Oct 2022 17:30:58 +0900 (JST)
Subject: [ruby-changes:73828] 56f2fd3bc9 (master): Use the dedicated function to check arity

https://git.ruby-lang.org/ruby.git/commit/?id=56f2fd3bc9

From 56f2fd3bc9bbc69abe75def25f89dac41eb19773 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 1 Oct 2022 16:18:03 +0900
Subject: Use the dedicated function to check arity

---
 struct.c        | 4 ++--
 vm_insnhelper.c | 9 +++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/struct.c b/struct.c
index 3a5dc8b7d4..9793133f80 100644
--- a/struct.c
+++ b/struct.c
@@ -742,7 +742,7 @@ rb_struct_initialize_m(int argc, const VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/struct.c#L742
     switch (rb_struct_s_keyword_init(klass)) {
       default:
         if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) {
-            rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc);
+            rb_error_arity(argc, 0, 0);
         }
         keyword_init = true;
         break;
@@ -1800,7 +1800,7 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/struct.c#L1800
         return Qnil;
     }
     if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) {
-        rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc);
+        rb_error_arity(argc, 0, 0);
     }
 
     if (RHASH_SIZE(argv[0]) < num_members) {
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 98138f5922..03796d2ad1 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -428,16 +428,17 @@ rb_vm_pop_frame(rb_execution_context_t *ec) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L428
 static inline VALUE
 rb_arity_error_new(int argc, int min, int max)
 {
-    VALUE err_mess = 0;
+    VALUE err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d", argc, min);
     if (min == max) {
-        err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d)", argc, min);
+        /* max is not needed */
     }
     else if (max == UNLIMITED_ARGUMENTS) {
-        err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d+)", argc, min);
+        rb_str_cat_cstr(err_mess, "+");
     }
     else {
-        err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d..%d)", argc, min, max);
+        rb_str_catf(err_mess, "..%d", max);
     }
+    rb_str_cat_cstr(err_mess, ")");
     return rb_exc_new3(rb_eArgError, err_mess);
 }
 
-- 
cgit v1.2.1


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

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