Module: Kernel

Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#caller_ext(argv[], self) ⇒ Object

like in ‘Kernel#caller’



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/ruby_ext_backtrace/ruby_ext_backtrace.c', line 101

static VALUE rb_caller_ext(int argc, VALUE argv[], VALUE self){
  int trim = 1;
  if(argc > 1)
    rb_raise(rb_eArgError, "wrong number of arguments(%d for 0-1)", argc);
  if(argc > 0){
    trim = FIX2INT(argv[0]);
  }

  rb_thread_t *th = GET_THREAD();
  //we know frames count, thus array size is known too, eliminate relocations
  int frames = (int)((rb_control_frame_t*)(th->stack + th->stack_size) - th->cfp - 3 - trim);

  VALUE res = rb_ary_new2(frames);
  vm_backtrace_each_ext(th, trim, NULL/*init func*/, backtrace_iter, (void*)res /*param*/);
  return res;
}