ruby-changes:65263
From: Nobuyoshi <ko1@a...>
Date: Mon, 15 Feb 2021 18:29:56 +0900 (JST)
Subject: [ruby-changes:65263] 4f47d655e3 (master): Added Thread::Backtrace.limit [Feature #17479]
https://git.ruby-lang.org/ruby.git/commit/?id=4f47d655e3 From 4f47d655e357a7f09943f199969b437a25665ed2 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 15 Feb 2021 15:58:45 +0900 Subject: Added Thread::Backtrace.limit [Feature #17479] --- common.mk | 2 ++ test/ruby/test_rubyoptions.rb | 2 ++ vm_backtrace.c | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/common.mk b/common.mk index c9507d2..ebbe3a1 100644 --- a/common.mk +++ b/common.mk @@ -15613,10 +15613,12 @@ vm_backtrace.$(OBJEXT): $(hdrdir)/ruby.h https://github.com/ruby/ruby/blob/trunk/common.mk#L15613 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 08f9e98..0d42604 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -77,6 +77,8 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L77 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 f2cc212..4f1d14a 100644 --- a/vm_backtrace.c +++ b/vm_backtrace.c @@ -11,6 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L11 #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) https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L840 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) https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L1208 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/