diff --git a/common.mk b/common.mk index c9507d2ad8..ebbe3a18df 100644 --- a/common.mk +++ b/common.mk @@ -15613,10 +15613,12 @@ vm_backtrace.$(OBJEXT): $(hdrdir)/ruby.h vm_backtrace.$(OBJEXT): $(hdrdir)/ruby/ruby.h vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/array.h vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/compilers.h +vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/error.h vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/gc.h vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/imemo.h vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/serial.h vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/static_assert.h +vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/string.h vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/vm.h vm_backtrace.$(OBJEXT): $(top_srcdir)/internal/warnings.h vm_backtrace.$(OBJEXT): {$(VPATH)}assert.h diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 08f9e98dcf..0d42604b87 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -77,6 +77,8 @@ class TestRubyOptions < Test::Unit::TestCase assert_in_out_err(%w(--backtrace-limit=3), code, [], [/.*unhandled exception\n/, *[/^\tfrom .*\n/]*3, /^\t \.{3} \d+ levels\.{3}\n/]) + assert_kind_of(Integer, Thread::Backtrace.limit) + assert_in_out_err(%w(--backtrace-limit=1), "p Thread::Backtrace.limit", ['1'], []) end def test_warning diff --git a/vm_backtrace.c b/vm_backtrace.c index f2cc21294c..4f1d14af31 100644 --- a/vm_backtrace.c +++ b/vm_backtrace.c @@ -11,6 +11,7 @@ #include "eval_intern.h" #include "internal.h" +#include "internal/error.h" #include "internal/vm.h" #include "iseq.h" #include "ruby/debug.h" @@ -839,6 +840,12 @@ backtrace_load_data(VALUE self, VALUE str) return self; } +static VALUE +backtrace_limit(VALUE self) +{ + return LONG2NUM(rb_backtrace_length_limit); +} + VALUE rb_ec_backtrace_str_ary(const rb_execution_context_t *ec, long lev, long n) { @@ -1201,6 +1208,7 @@ Init_vm_backtrace(void) rb_define_alloc_func(rb_cBacktrace, backtrace_alloc); rb_undef_method(CLASS_OF(rb_cBacktrace), "new"); rb_marshal_define_compat(rb_cBacktrace, rb_cArray, backtrace_dump_data, backtrace_load_data); + rb_define_singleton_method(rb_cBacktrace, "limit", backtrace_limit, 0); /* * An object representation of a stack frame, initialized by