|
3 | 3 | #include "ruby.h"
|
4 | 4 | #include "ruby/version.h"
|
5 | 5 |
|
6 |
| -// ========= Private Ruby API ========= |
7 |
| -// from eval_intern.h |
8 |
| -VALUE rb_f_eval(int argc, const VALUE *argv, VALUE self); |
9 |
| -// from internal/vm.h |
10 |
| -PUREFUNC(VALUE rb_vm_top_self(void)); |
11 |
| -// from vm_core.h |
12 |
| -typedef struct rb_control_frame_struct { |
13 |
| - const VALUE *pc; /* cfp[0] */ |
14 |
| - VALUE *sp; /* cfp[1] */ |
15 |
| - const void *iseq; /* cfp[2] */ |
16 |
| - VALUE self; /* cfp[3] / block[0] */ |
17 |
| - const VALUE *ep; /* cfp[4] / block[1] */ |
18 |
| -} rb_control_frame_t; |
19 |
| - |
20 |
| -typedef struct rb_execution_context_struct { |
21 |
| - /* execution information */ |
22 |
| - VALUE *vm_stack; /* must free, must mark */ |
23 |
| - size_t vm_stack_size; /* size in word (byte size / sizeof(VALUE)) */ |
24 |
| - rb_control_frame_t *cfp; |
25 |
| -} rb_execution_context_t; |
26 |
| - |
27 |
| -// from vm.c and vm_core.h |
28 |
| -RUBY_EXTERN struct rb_execution_context_struct *ruby_current_ec; |
29 |
| -#define GET_EC() (ruby_current_ec) |
30 |
| -rb_control_frame_t * |
31 |
| -rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, |
32 |
| - const rb_control_frame_t *cfp); |
33 |
| -// ====== End of Private Ruby API ===== |
34 |
| - |
35 |
| -VALUE |
36 |
| -ruby_eval_string_value_from_file(VALUE str, VALUE file) { |
37 |
| - rb_execution_context_t *ec = GET_EC(); |
38 |
| - rb_control_frame_t *cfp = |
39 |
| - ec ? rb_vm_get_ruby_level_next_cfp(ec, ec->cfp) : NULL; |
40 |
| - VALUE self = cfp ? cfp->self : rb_vm_top_self(); |
41 |
| -#define argc 4 |
42 |
| - const VALUE argv[argc] = {str, Qnil, file, INT2FIX(1)}; |
43 |
| - return rb_f_eval(argc, argv, self); |
44 |
| -#undef argc |
45 |
| -} |
46 |
| - |
47 | 6 | static VALUE rb_eval_string_value_protect_thunk(VALUE str) {
|
48 |
| - return ruby_eval_string_value_from_file(str, rb_utf8_str_new("eval", 4)); |
| 7 | + const ID id_eval = rb_intern("eval"); |
| 8 | + VALUE binding = rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING")); |
| 9 | + const VALUE file = rb_utf8_str_new("eval", 4); |
| 10 | + VALUE args[3] = {str, binding, file}; |
| 11 | + return rb_funcallv(rb_mKernel, id_eval, 3, args); |
49 | 12 | }
|
50 | 13 |
|
51 |
| -// TODO(katei): This API should be moved to CRuby itself. |
52 |
| -VALUE |
53 |
| -rb_eval_string_value_protect(VALUE str, int *pstate) { |
| 14 | +static VALUE rb_eval_string_value_protect(VALUE str, int *pstate) { |
54 | 15 | return rb_protect(rb_eval_string_value_protect_thunk, str, pstate);
|
55 | 16 | }
|
56 | 17 |
|
|
0 commit comments