Permalink
Browse files

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

  • Loading branch information...
matz committed May 31, 2017
1 parent 2837de9 commit ff7df939ba88389cd7f1a2226b3e1d49822711b3
Showing with 19 additions and 18 deletions.
  1. +1 −0 include/mruby/error.h
  2. +17 −1 src/backtrace.c
  3. +1 −17 src/error.c
View
@@ -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, ...);
View
@@ -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));
View
@@ -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 */

0 comments on commit ff7df93

Please sign in to comment.