diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-18 07:48:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-18 07:48:37 +0000 |
commit | 8ffb23c2e1f2f292c8ed85b51ffb85f4811e5a9e (patch) | |
tree | dd6d92bd3456620b372c4f8750aadf5597446f31 | |
parent | 6607266ef81e6ed6ddf90ba982d6609daaa471bc (diff) | |
download | ruby-8ffb23c2e1f2f292c8ed85b51ffb85f4811e5a9e.tar.gz |
proc.c: rb_block_min_max_arity
* proc.c (rb_block_min_max_arity): new function to get arity range
from the current block.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | proc.c | 24 |
2 files changed, 21 insertions, 4 deletions
diff --git a/internal.h b/internal.h index e6d50ebcda..c040172f3e 100644 --- a/internal.h +++ b/internal.h @@ -1477,6 +1477,7 @@ ID rb_id_attrget(ID id); VALUE rb_proc_location(VALUE self); st_index_t rb_hash_proc(st_index_t hash, VALUE proc); int rb_block_arity(void); +int rb_block_min_max_arity(int *max); VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val); VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val); @@ -930,7 +930,7 @@ rb_iseq_min_max_arity(const rb_iseq_t *iseq, int *max) } static int -rb_block_min_max_arity(const struct rb_block *block, int *max) +rb_vm_block_min_max_arity(const struct rb_block *block, int *max) { again: switch (vm_block_type(block)) { @@ -966,7 +966,7 @@ rb_proc_min_max_arity(VALUE self, int *max) { rb_proc_t *proc; GetProcPtr(self, proc); - return rb_block_min_max_arity(&proc->block, max); + return rb_vm_block_min_max_arity(&proc->block, max); } int @@ -975,7 +975,7 @@ rb_proc_arity(VALUE self) rb_proc_t *proc; int max, min; GetProcPtr(self, proc); - min = rb_block_min_max_arity(&proc->block, &max); + min = rb_vm_block_min_max_arity(&proc->block, &max); return (proc->is_lambda ? min == max : max != UNLIMITED_ARGUMENTS) ? min : -min-1; } @@ -1015,7 +1015,7 @@ rb_block_arity(void) } block_setup(&block, block_handler); - min = rb_block_min_max_arity(&block, &max); + min = rb_vm_block_min_max_arity(&block, &max); switch (vm_block_type(&block)) { case block_handler_type_symbol: @@ -1035,6 +1035,22 @@ rb_block_arity(void) } } +int +rb_block_min_max_arity(int *max) +{ + rb_thread_t *th = GET_THREAD(); + rb_control_frame_t *cfp = th->ec.cfp; + VALUE block_handler = rb_vm_frame_block_handler(cfp); + struct rb_block block; + + if (block_handler == VM_BLOCK_HANDLER_NONE) { + rb_raise(rb_eArgError, "no block given"); + } + + block_setup(&block, block_handler); + return rb_vm_block_min_max_arity(&block, max); +} + const rb_iseq_t * rb_proc_get_iseq(VALUE self, int *is_proc) { |