Skip to content

Instantly share code, notes, and snippets.

@tomstuart
Created June 25, 2023 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomstuart/d59cd53006dce11cc0d598ee31411e4c to your computer and use it in GitHub Desktop.
Save tomstuart/d59cd53006dce11cc0d598ee31411e4c to your computer and use it in GitHub Desktop.
Read `--backtrace-limit` from `RUBYOPT`, default it to 5 and allow it to be set to -1
diff --git a/error.c b/error.c
index 8aa081c198..d51ea349e0 100644
--- a/error.c
+++ b/error.c
@@ -66,7 +66,7 @@ VALUE rb_iseqw_local_variables(VALUE iseqval);
VALUE rb_iseqw_new(const rb_iseq_t *);
int rb_str_end_with_asciichar(VALUE str, int c);
-long rb_backtrace_length_limit = -1;
+long rb_backtrace_length_limit = 5;
VALUE rb_eEAGAIN;
VALUE rb_eEWOULDBLOCK;
VALUE rb_eEINPROGRESS;
diff --git a/ruby.c b/ruby.c
index c27f44edb3..09556b5008 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1522,10 +1522,10 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
opt->dump |= DUMP_BIT(help);
goto switch_end;
}
- else if (is_option_with_arg("backtrace-limit", Qfalse, Qfalse)) {
+ else if (is_option_with_arg("backtrace-limit", Qfalse, Qtrue)) {
char *e;
long n = strtol(s, &e, 10);
- if (errno == ERANGE || n < 0 || *e) rb_raise(rb_eRuntimeError, "wrong limit for backtrace length");
+ if (errno == ERANGE || n < -1 || *e) rb_raise(rb_eRuntimeError, "wrong limit for backtrace length");
rb_backtrace_length_limit = n;
}
else {
@tomstuart
Copy link
Author

To install Ruby with this patch:

ruby-install --patch https://gist.github.com/tomstuart/d59cd53006dce11cc0d598ee31411e4c/raw 3.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment