Commit 5859a204 authored by Kazuki Tsujimoto's avatar Kazuki Tsujimoto

Fix SEGV when calling Proc object created by Proc.new

parent 2b9ed5ac
......@@ -50,6 +50,22 @@ mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func)
return p;
}
static mrb_value
mrb_proc_initialize(mrb_state *mrb, mrb_value self)
{
mrb_value blk = mrb->stack[mrb->ci->argc+1];
if (!mrb_nil_p(blk)) {
*mrb_proc_ptr(self) = *mrb_proc_ptr(blk);
}
else {
/* Calling Proc.new without a block is not implemented yet */
mrb_raise(mrb, E_ARGUMENT_ERROR, "tried to create Proc object without a block");
}
return self;
}
int
mrb_proc_cfunc_p(struct RProc *p)
{
......@@ -86,6 +102,8 @@ mrb_init_proc(mrb_state *mrb)
mrb->proc_class = mrb_define_class(mrb, "Proc", mrb->object_class);
mrb_define_method(mrb, mrb->proc_class, "initialize", mrb_proc_initialize, ARGS_NONE());
m = mrb_proc_new(mrb, call_irep);
mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "call"), m);
mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "[]"), m);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment