83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'ext/binding_of_caller/binding_of_caller.c', line 83
static VALUE binding_of_caller(VALUE self, VALUE rb_level)
{
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
int level = FIX2INT(rb_level);
// attempt to locate the nth parent control frame
for (int i = 0; i < level; i++)
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
// if did not find a valid one, then search for a valid one
if (!valid_frame_p(cfp))
cfp = find_valid_frame(cfp);
VALUE bindval = binding_alloc(rb_cBinding);
rb_binding_t *bind;
if (cfp == 0) {
rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber.");
}
GetBindingPtr(bindval, bind);
bind->env = rb_vm_make_env_object(th, cfp);
bind->filename = cfp->iseq->filename;
bind->line_no = rb_vm_get_sourceline(cfp);
return bindval;
}
|