Project

General

Profile

Bug #10466 ยป rb_eval_string_wrap_cref.patch

jeremyevans0 (Jeremy Evans), 07/23/2019 02:58 AM

View differences:

vm_eval.c
1481 1481
    return rb_protect(eval_string_protect, (VALUE)str, pstate);
1482 1482
}
1483 1483

  
1484
struct eval_string_wrap_arg {
1485
    VALUE top_self;
1486
    VALUE klass;
1487
    const char *str;
1488
};
1489

  
1490
static VALUE
1491
eval_string_wrap_protect(VALUE data)
1492
{
1493
    const struct eval_string_wrap_arg *const arg = (struct eval_string_wrap_arg*)data;
1494
    rb_cref_t *cref = rb_vm_cref_new_toplevel();
1495
    cref->klass = arg->klass;
1496
    return eval_string_with_cref(arg->top_self, rb_str_new_cstr(arg->str), cref, rb_str_new_cstr("eval"), 1);
1497
}
1498

  
1484 1499
/**
1485 1500
 * Evaluates the given string under a module binding in an isolated binding.
1486 1501
 * This is same as the binding for loaded libraries on "load('foo', true)".
......
1500 1515
    VALUE self = th->top_self;
1501 1516
    VALUE wrapper = th->top_wrapper;
1502 1517
    VALUE val;
1518
    struct eval_string_wrap_arg data;
1503 1519

  
1504 1520
    th->top_wrapper = rb_module_new();
1505 1521
    th->top_self = rb_obj_clone(rb_vm_top_self());
1506 1522
    rb_extend_object(th->top_self, th->top_wrapper);
1507 1523

  
1508
    val = rb_eval_string_protect(str, &state);
1524
    data.top_self = th->top_self;
1525
    data.klass = th->top_wrapper;
1526
    data.str = str;
1527

  
1528
    val = rb_protect(eval_string_wrap_protect, (VALUE)&data, &state);
1509 1529

  
1510 1530
    th->top_self = self;
1511 1531
    th->top_wrapper = wrapper;
1512
-