summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal.h1
-rw-r--r--proc.c24
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);
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)
{