mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* hash.c (rb_hash_set_default_proc): checks arity of defalt_proc
of a Hash. [ruby-core:26087] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5f01ed26f2
commit
ba3bfda7a2
4 changed files with 16 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Oct 24 14:28:40 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* object.c (rb_obj_cmp): defines Object#<=>. [ruby-core:24063]
|
||||
|
|
6
hash.c
6
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;
|
||||
|
|
|
@ -305,6 +305,7 @@ VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE
|
|||
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);
|
||||
|
|
8
proc.c
8
proc.c
|
@ -223,8 +223,8 @@ proc_clone(VALUE self)
|
|||
*
|
||||
*/
|
||||
|
||||
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 @@ proc_curry(int argc, VALUE *argv, VALUE self)
|
|||
}
|
||||
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 @@ Init_Proc(void)
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue