ruby-changes:13670
From: matz <ko1@a...>
Date: Sun, 25 Oct 2009 01:53:27 +0900 (JST)
Subject: [ruby-changes:13670] Ruby:r25455 (trunk): * hash.c (rb_hash_set_default_proc): checks arity of defalt_proc
matz 2009-10-25 01:53:11 +0900 (Sun, 25 Oct 2009) New Revision: 25455 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25455 Log: * hash.c (rb_hash_set_default_proc): checks arity of defalt_proc of a Hash. [ruby-core:26087] Modified files: trunk/ChangeLog trunk/hash.c trunk/include/ruby/intern.h trunk/proc.c Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 25454) +++ include/ruby/intern.h (revision 25455) @@ -305,6 +305,7 @@ VALUE rb_proc_call(VALUE, VALUE); VALUE rb_proc_call_with_block(VALUE, int argc, VALUE *argv, VALUE); int rb_proc_arity(VALUE); +VALUE rb_proc_lambda_p(VALUE); VALUE rb_binding_new(void); VALUE rb_obj_method(VALUE, VALUE); VALUE rb_method_call(int, VALUE*, VALUE); Index: ChangeLog =================================================================== --- ChangeLog (revision 25454) +++ ChangeLog (revision 25455) @@ -1,3 +1,8 @@ +Sat Oct 24 14:28:40 2009 Yukihiro Matsumoto <matz@r...> + + * hash.c (rb_hash_set_default_proc): checks arity of defalt_proc + of a Hash. [ruby-core:26087] + Sat Oct 24 13:38:45 2009 Yukihiro Matsumoto <matz@r...> * object.c (rb_obj_cmp): defines Object#<=>. [ruby-core:24063] Index: proc.c =================================================================== --- proc.c (revision 25454) +++ proc.c (revision 25455) @@ -223,8 +223,8 @@ * */ -static VALUE -proc_lambda_p(VALUE procval) +VALUE +rb_proc_lambda_p(VALUE procval) { rb_proc_t *proc; GetProcPtr(procval, proc); @@ -1971,7 +1971,7 @@ } else { sarity = FIX2INT(arity); - if (proc_lambda_p(self) && (sarity < marity || (sarity > marity && !opt))) { + if (rb_proc_lambda_p(self) && (sarity < marity || (sarity > marity && !opt))) { rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", sarity, marity); } } @@ -2028,7 +2028,7 @@ rb_define_method(rb_cProc, "eql?", proc_eq, 1); rb_define_method(rb_cProc, "hash", proc_hash, 0); rb_define_method(rb_cProc, "to_s", proc_to_s, 0); - rb_define_method(rb_cProc, "lambda?", proc_lambda_p, 0); + rb_define_method(rb_cProc, "lambda?", rb_proc_lambda_p, 0); rb_define_method(rb_cProc, "binding", proc_binding, 0); rb_define_method(rb_cProc, "curry", proc_curry, -1); rb_define_method(rb_cProc, "source_location", rb_proc_location, 0); Index: hash.c =================================================================== --- hash.c (revision 25454) +++ hash.c (revision 25455) @@ -667,6 +667,7 @@ 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_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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/