Skip to content

Commit

Permalink
Backtrace-limit option in command line have precedence over RUBYOPT
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Aug 10, 2023
1 parent f702db0 commit bcabaaa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 4 additions & 6 deletions ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ cmdline_options_init(ruby_cmdline_options_t *opt)
#elif defined(YJIT_FORCE_ENABLE)
opt->features.set |= FEATURE_BIT(yjit);
#endif
opt->backtrace_length_limit = -1;
opt->backtrace_length_limit = -2; /* invalid value */

return opt;
}
Expand Down Expand Up @@ -893,7 +893,6 @@ moreswitches(const char *s, ruby_cmdline_options_t *opt, int envopt)
VALUE int_enc_name = opt->intern.enc.name;
ruby_features_t feat = opt->features;
ruby_features_t warn = opt->warn;
int backtrace_length_limit = opt->backtrace_length_limit;

while (ISSPACE(*s)) s++;
if (!*s) return;
Expand Down Expand Up @@ -944,9 +943,6 @@ moreswitches(const char *s, ruby_cmdline_options_t *opt, int envopt)
}
FEATURE_SET_RESTORE(opt->features, feat);
FEATURE_SET_RESTORE(opt->warn, warn);
if (backtrace_length_limit >= 0) {
opt->backtrace_length_limit = backtrace_length_limit;
}

ruby_xfree(ptr);
/* get rid of GC */
Expand Down Expand Up @@ -1453,7 +1449,9 @@ proc_long_options(ruby_cmdline_options_t *opt, const char *s, long argc, char **
if (errno == ERANGE || n < -1 || n > INT_MAX || *e) {
rb_raise(rb_eRuntimeError, "wrong limit for backtrace length");
}
opt->backtrace_length_limit = (int)n;
else if (opt->backtrace_length_limit < -1) {
opt->backtrace_length_limit = (int)n;
}
}
else {
rb_raise(rb_eRuntimeError,
Expand Down
1 change: 1 addition & 0 deletions test/ruby/test_rubyoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def test_backtrace_limit
env = {"RUBYOPT" => "--backtrace-limit=5"}
assert_in_out_err([env], "p Thread::Backtrace.limit", ['5'], [])
assert_in_out_err([env, "--backtrace-limit=1"], "p Thread::Backtrace.limit", ['1'], [])
assert_in_out_err([env, "--backtrace-limit=-1"], "p Thread::Backtrace.limit", ['-1'], [])
if (int_max = RbConfig::LIMITS["INT_MAX"]) < RbConfig::LIMITS["LONG_MAX"]
assert_in_out_err(%W(--backtrace-limit=#{int_max+1}), "p Thread::Backtrace.limit",
[], /wrong limit for backtrace length/)
Expand Down

0 comments on commit bcabaaa

Please sign in to comment.