Permalink
Browse files

Merge pull request #37 from k-tsj/fix-proc-segv

Fix SEGV when calling Proc object created by Proc.new
  • Loading branch information...
2 parents 484a5f6 + 5859a20 commit 7feb68eb9030dc15f216479b45533428534b050e @matz matz committed Apr 22, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 src/proc.c
View
@@ -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);

0 comments on commit 7feb68e

Please sign in to comment.