proc_call_under.patch

Yusuke Endoh, 04/17/2012 10:52 PM

Download (2.06 KB)

View differences:

proc.c
567 567
    return vret;
568 568
}
569 569

  
570
VALUE rb_proc_call_under(VALUE procval, VALUE under, VALUE self, VALUE values);
571

  
572
static VALUE
573
proc_call_under(int argc, VALUE *argv, VALUE procval)
574
{
575
    VALUE self, klass, values;
576
    rb_scan_args(argc, argv, "1*", &self, &values);
577
    if (SPECIAL_CONST_P(self)) {
578
	klass = Qnil;
579
    }
580
    else {
581
	klass = rb_singleton_class(self);
582
    }
583
    return rb_proc_call_under(procval, klass, self, values);
584
}
585

  
570 586
#if SIZEOF_LONG > SIZEOF_INT
571 587
static inline int
572 588
check_argc(long argc)
......
2183 2199
    rb_define_method(rb_cProc, "[]", proc_call, -1);
2184 2200
    rb_define_method(rb_cProc, "===", proc_call, -1);
2185 2201
    rb_define_method(rb_cProc, "yield", proc_call, -1);
2202
    rb_define_method(rb_cProc, "call_under", proc_call_under, -1);
2186 2203
#endif
2187 2204
    rb_define_method(rb_cProc, "to_proc", proc_to_proc, 0);
2188 2205
    rb_define_method(rb_cProc, "arity", proc_arity, 0);
vm_eval.c
1262 1262
    }
1263 1263
}
1264 1264

  
1265
static inline VALUE
1266
invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
1267
		    VALUE self, int argc, const VALUE *argv,
1268
		    const rb_block_t *blockptr, const NODE *cref);
1269

  
1270
VALUE
1271
rb_proc_call_under(VALUE procval, VALUE under, VALUE self, VALUE values)
1272
{
1273
    rb_thread_t *th = GET_THREAD();
1274
    rb_block_t block;
1275
    NODE *cref;
1276
    rb_proc_t *proc;
1277

  
1278
    GetProcPtr(procval, proc);
1279
    block = proc->block;
1280
    block.self = self;
1281
    cref = vm_cref_push(th, under, NOEX_PUBLIC, &proc->block);
1282
    cref->flags |= NODE_FL_CREF_PUSHED_BY_EVAL;
1283

  
1284
    return invoke_block_from_c(th, &block, self,
1285
	    RARRAY_LENINT(values), RARRAY_PTR(values),
1286
	    GC_GUARDED_PTR_REF(th->cfp->lfp[0]), cref);
1287
}
1288

  
1265 1289
/* string eval under the class/module context */
1266 1290
static VALUE
1267 1291
eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line)