Restore MRB_API function `mrb_exc_backtrace(mrb, exc)`; ref
MODIFY
include/mruby/error.h
include/mruby/error.h
@@ -25,6 +25,7 @@ MRB_API void mrb_sys_fail(mrb_state *mrb, const char *mesg);
MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
MRB_API mrb_value mrb_make_exception(mrb_state *mrb, int argc, const mrb_value *argv);
+MRB_API mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
MRB_API mrb_value mrb_get_backtrace(mrb_state *mrb);
MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...);

MODIFY
src/backtrace.c
src/backtrace.c
@@ -227,7 +227,23 @@ mrb_unpack_backtrace(mrb_state *mrb, mrb_value backtrace)
return backtrace;
}
-mrb_value
+MRB_API mrb_value
+mrb_exc_backtrace(mrb_state *mrb, mrb_value exc)
+{
+ mrb_sym attr_name;
+ mrb_value backtrace;
+
+ attr_name = mrb_intern_lit(mrb, "backtrace");
+ backtrace = mrb_iv_get(mrb, exc, attr_name);
+ if (mrb_nil_p(backtrace) || mrb_array_p(backtrace)) {
+ return backtrace;
+ }
+ backtrace = mrb_unpack_backtrace(mrb, backtrace);
+ mrb_iv_set(mrb, exc, attr_name, backtrace);
+ return backtrace;
+}
+
+MRB_API mrb_value
mrb_get_backtrace(mrb_state *mrb)
{
return mrb_unpack_backtrace(mrb, packed_backtrace(mrb));

MODIFY
src/error.c
src/error.c
@@ -164,22 +164,6 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
}
void mrb_keep_backtrace(mrb_state *mrb, mrb_value exc);
-mrb_value mrb_unpack_backtrace(mrb_state *mrb, mrb_value backtrace);
-
-static mrb_value
-exc_get_backtrace(mrb_state *mrb, mrb_value exc)
-{
- mrb_sym attr_name;
- mrb_value backtrace;
-
- attr_name = mrb_intern_lit(mrb, "backtrace");
- backtrace = mrb_iv_get(mrb, exc, attr_name);
- if (!mrb_array_p(backtrace)) {
- backtrace = mrb_unpack_backtrace(mrb, backtrace);
- mrb_iv_set(mrb, exc, attr_name, backtrace);
- }
- return backtrace;
-}
static void
set_backtrace(mrb_state *mrb, mrb_value exc, mrb_value backtrace)
@@ -498,7 +482,7 @@ mrb_init_exception(mrb_state *mrb)
mrb_define_method(mrb, exception, "to_s", exc_to_s, MRB_ARGS_NONE());
mrb_define_method(mrb, exception, "message", exc_message, MRB_ARGS_NONE());
mrb_define_method(mrb, exception, "inspect", exc_inspect, MRB_ARGS_NONE());
- mrb_define_method(mrb, exception, "backtrace", exc_get_backtrace, MRB_ARGS_NONE());
+ mrb_define_method(mrb, exception, "backtrace", mrb_exc_backtrace, MRB_ARGS_NONE());
mrb_define_method(mrb, exception, "set_backtrace", exc_set_backtrace, MRB_ARGS_REQ(1));
mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */

Restore MRB_API function `mrb_exc_backtrace(mrb, exc)`; ref 9644ad5