summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-24 16:53:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-24 16:53:11 +0000
commit2f93e39970c32520f347f65d5cd7fd4453f429ab (patch)
treeaf63a4163e4f225e89c36207e89d5b61c8b6947d /hash.c
parentf4593b97334b56095e875958dcfea36152959117 (diff)
downloadruby-2f93e39970c32520f347f65d5cd7fd4453f429ab.tar.gz
ruby-2f93e39970c32520f347f65d5cd7fd4453f429ab.tar.xz
ruby-2f93e39970c32520f347f65d5cd7fd4453f429ab.zip
* hash.c (rb_hash_set_default_proc): checks arity of defalt_proc
of a Hash. [ruby-core:26087] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 3fab523ae..6c8fa5e0c 100644
--- a/hash.c
+++ b/hash.c
@@ -667,6 +667,7 @@ static VALUE
rb_hash_set_default_proc(VALUE hash, VALUE proc)
{
VALUE b;
+ int n;
rb_hash_modify(hash);
b = rb_check_convert_type(proc, T_DATA, "Proc", "to_proc");
@@ -676,6 +677,11 @@ rb_hash_set_default_proc(VALUE hash, VALUE proc)
rb_obj_classname(proc));
}
proc = b;
+ n = rb_proc_arity(proc);
+ if (rb_proc_lambda_p(proc) && n != 2 && (n >= 0 || n < -3)) {
+ if (n < 0) n = -n-1;
+ rb_raise(rb_eTypeError, "default_proc takes two arguments (2 for %d)", n);
+ }
RHASH(hash)->ifnone = proc;
FL_SET(hash, HASH_PROC_DEFAULT);
return proc;