summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-18 07:48:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-18 07:48:37 +0000
commit8ffb23c2e1f2f292c8ed85b51ffb85f4811e5a9e (patch)
treedd6d92bd3456620b372c4f8750aadf5597446f31 /proc.c
parent6607266ef81e6ed6ddf90ba982d6609daaa471bc (diff)
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
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/proc.c b/proc.c
index ac182a9eaa..0a3e132640 100644
--- a/proc.c
+++ b/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)
{