mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
6607266ef8
commit
8ffb23c2e1
2 changed files with 21 additions and 4 deletions
|
@ -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);
|
||||
|
||||
|
|
24
proc.c
24
proc.c
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue