diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-14 21:10:34 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-14 21:10:34 +0000 |
commit | 7316302483182a73136b00ad368585e551cbd86f (patch) | |
tree | d32188711001581a5e7e21d6669f6c4e91fcb497 /vm_insnhelper.c | |
parent | 35c356ea72094dbbf1397d8f5acd065bd23d1177 (diff) | |
download | ruby-7316302483182a73136b00ad368585e551cbd86f.tar.gz |
* include/ruby/intern.h: Add rb_check_arity, rb_error_arity [#6085]
* array.c: Use rb_check_arity / rb_error_arity
* class.c: ditto
* enumerator.c: ditto
* eval.c: ditto
* file.c: ditto
* hash.c: ditto
* numeric.c: ditto
* proc.c: ditto
* process.c: ditto
* random.c: ditto
* re.c: ditto
* signal.c: ditto
* string.c: ditto
* struct.c: ditto
* transcode.c: ditto
* vm_eval.c: ditto
* vm_insnhelper.c: ditto & implementation of rb_error_arity
* test/ruby/test_arity.rb: tests for above
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index f471ca5ccb..bcdf0d7a34 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -163,6 +163,11 @@ unknown_keyword_error(const rb_iseq_t *iseq, VALUE hash) rb_raise(rb_eArgError, msg, RSTRING_PTR(keys)); } +void +rb_error_arity(int argc, int min, int max) { + rb_exc_raise(rb_arg_error_new(argc, min, max)); +} + #define VM_CALLEE_SETUP_ARG(ret, th, iseq, orig_argc, orig_argv, block) \ if (LIKELY((iseq)->arg_simple & 0x01)) { \ /* simple check */ \ @@ -354,10 +359,7 @@ call_cfunc(VALUE (*func)(), VALUE recv, { /* printf("len: %d, argc: %d\n", len, argc); */ - if (len >= 0 && argc != len) { - rb_raise(rb_eArgError, "wrong number of arguments(%d for %d)", - argc, len); - } + if (len >= 0) rb_check_arity(argc, len, len); switch (len) { case -2: @@ -581,17 +583,13 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, break; } case VM_METHOD_TYPE_ATTRSET:{ - if (num != 1) { - rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", num); - } + rb_check_arity(num, 1, 1); val = rb_ivar_set(recv, me->def->body.attr.id, *(cfp->sp - 1)); cfp->sp -= 2; break; } case VM_METHOD_TYPE_IVAR:{ - if (num != 0) { - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", num); - } + rb_check_arity(num, 0, 0); val = rb_attr_get(recv, me->def->body.attr.id); cfp->sp -= 1; break; |