modules/mruby/src/proc.c in webruby-0.2.2 vs modules/mruby/src/proc.c in webruby-0.2.4

- old
+ new

@@ -20,10 +20,11 @@ p = (struct RProc*)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class); p->target_class = (mrb->c->ci) ? mrb->c->ci->target_class : 0; p->body.irep = irep; p->env = 0; + mrb_irep_incref(mrb, irep); return p; } static inline void @@ -78,10 +79,13 @@ void mrb_proc_copy(struct RProc *a, struct RProc *b) { a->flags = b->flags; a->body = b->body; + if (!MRB_PROC_CFUNC_P(a)) { + a->body.irep->refcnt++; + }; a->target_class = b->target_class; a->env = b->env; } static mrb_value @@ -179,19 +183,18 @@ void mrb_init_proc(mrb_state *mrb) { struct RProc *m; - mrb_irep *call_irep = (mrb_irep *)mrb_alloca(mrb, sizeof(mrb_irep)); + mrb_irep *call_irep = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep)); static const mrb_irep mrb_irep_zero = { 0 }; - if ( call_iseq == NULL || call_irep == NULL ) + if (call_irep == NULL) return; *call_irep = mrb_irep_zero; call_irep->flags = MRB_ISEQ_NO_FREE; - call_irep->idx = -1; call_irep->iseq = call_iseq; call_irep->ilen = 1; mrb->proc_class = mrb_define_class(mrb, "Proc", mrb->object_class); MRB_SET_INSTANCE_TT(mrb->proc_class, MRB_TT_PROC); @@ -199,11 +202,11 @@ mrb_define_method(mrb, mrb->proc_class, "initialize", mrb_proc_initialize, MRB_ARGS_NONE()); mrb_define_method(mrb, mrb->proc_class, "initialize_copy", mrb_proc_init_copy, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->proc_class, "arity", mrb_proc_arity, MRB_ARGS_NONE()); m = mrb_proc_new(mrb, call_irep); - mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern2(mrb, "call", 4), m); - mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern2(mrb, "[]", 2), m); + mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern_lit(mrb, "call"), m); + mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern_lit(mrb, "[]"), m); mrb_define_class_method(mrb, mrb->kernel_module, "lambda", proc_lambda, MRB_ARGS_NONE()); /* 15.3.1.2.6 */ mrb_define_method(mrb, mrb->kernel_module, "lambda", proc_lambda, MRB_ARGS_NONE()); /* 15.3.1.3.27 */ }