Skip to content

Commit

Permalink
Fix SEGV when calling Proc object created by Proc.new
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tsj committed Apr 22, 2012
1 parent 2b9ed5a commit 5859a20
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/proc.c
Expand Up @@ -50,6 +50,22 @@ mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func)
return p; 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 int
mrb_proc_cfunc_p(struct RProc *p) mrb_proc_cfunc_p(struct RProc *p)
{ {
Expand Down Expand Up @@ -86,6 +102,8 @@ mrb_init_proc(mrb_state *mrb)


mrb->proc_class = mrb_define_class(mrb, "Proc", mrb->object_class); 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); 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, "call"), m);
mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "[]"), m); mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "[]"), m);
Expand Down

0 comments on commit 5859a20

Please sign in to comment.