1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* vm_backtrace.c (vm_backtrace_to_ary): support range argument

like Array#[].
  [ruby-core:50092] [ruby-trunk - Feature #7434]
  Test and document is not available. Please help us.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2012-11-29 00:12:49 +00:00
parent b76b6b5c98
commit 3d47e7b285
2 changed files with 50 additions and 16 deletions

View file

@ -1,3 +1,10 @@
Thu Nov 29 09:10:17 2012 Koichi Sasada <ko1@atdot.net>
* vm_backtrace.c (vm_backtrace_to_ary): support range argument
like Array#[].
[ruby-core:50092] [ruby-trunk - Feature #7434]
Test and document is not available. Please help us.
Thu Nov 29 06:46:33 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* thread.c (thread_start_func_2): small cleanups.

View file

@ -699,33 +699,60 @@ vm_backtrace_to_ary(rb_thread_t *th, int argc, VALUE *argv, int lev_default, int
{
VALUE level, vn;
int lev, n;
VALUE btval = backtrace_object(th);
rb_backtrace_t *bt;
GetCoreDataFromValue(btval, rb_backtrace_t, bt);
rb_scan_args(argc, argv, "02", &level, &vn);
lev = NIL_P(level) ? lev_default : NUM2INT(level);
if (NIL_P(vn)) {
n = 0;
}
else {
n = NUM2INT(vn);
if (n == 0) {
return rb_ary_new();
switch (argc) {
case 0:
lev = lev_default + lev_plus;
n = bt->backtrace_size - lev;
break;
case 1:
{
long beg, len;
switch (rb_range_beg_len(level, &beg, &len, bt->backtrace_size - lev_plus, 0)) {
case Qfalse:
lev = NUM2LONG(level);
if (lev < 0) {
rb_raise(rb_eArgError, "negative level (%d)", lev);
}
lev += lev_plus;
n = bt->backtrace_size - lev;
break;
case Qnil:
return Qnil;
default:
lev = beg + lev_plus;
n = len;
break;
}
break;
}
case 2:
lev = NUM2LONG(level);
if (lev < 0) {
rb_raise(rb_eArgError, "negative level (%d)", lev);
}
lev += lev_plus;
n = NUM2LONG(vn);
break;
default:
lev = n = 0; /* to avoid warning */
break;
}
if (lev < 0) {
rb_raise(rb_eArgError, "negative level (%d)", lev);
}
if (n < 0) {
rb_raise(rb_eArgError, "negative n (%d)", n);
if (n == 0) {
return rb_ary_new();
}
if (to_str) {
return vm_backtrace_str_ary(th, lev+lev_plus, n);
return backtrace_to_str_ary(btval, lev, n);
}
else {
return vm_backtrace_location_ary(th, lev+lev_plus, n);
return backtrace_to_location_ary(btval, lev, n);
}
}