diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-27 04:34:30 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-27 04:34:30 +0900 |
| commit | 5b8229715df0d676367ab9d5c38a658b043781b3 (patch) | |
| tree | 551cbeea4e1e17e347d418551bd504557430d736 /src | |
| parent | 0c1c4416e7c96cf589dbeee2103fa9432dc17473 (diff) | |
| download | mruby-5b8229715df0d676367ab9d5c38a658b043781b3.tar.gz mruby-5b8229715df0d676367ab9d5c38a658b043781b3.zip | |
revert 38e9ce21 and API changed; mrb_get_backtrace() -> renamed to mrb_exc_backtrace since this is a backtrace method implementation of Exception; mrb_get_backtrace_at() -> removed; mrb_get_backtrace() -> added to get backtrace in array (like caller)
Diffstat (limited to 'src')
| -rw-r--r-- | src/backtrace.c | 10 | ||||
| -rw-r--r-- | src/error.c | 4 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/backtrace.c b/src/backtrace.c index a61d14e0c..6469fc069 100644 --- a/src/backtrace.c +++ b/src/backtrace.c @@ -12,6 +12,7 @@ #include "mruby/string.h" #include "mruby/class.h" #include "mruby/debug.h" +#include "mruby/error.h" typedef void (*output_stream_func)(mrb_state*, void*, int, const char*, ...); @@ -151,7 +152,7 @@ mrb_print_backtrace(mrb_state *mrb) } mrb_value -mrb_get_backtrace(mrb_state *mrb, mrb_value self) +mrb_exc_backtrace(mrb_state *mrb, mrb_value self) { mrb_value ary; @@ -162,11 +163,14 @@ mrb_get_backtrace(mrb_state *mrb, mrb_value self) } mrb_value -mrb_get_backtrace_at(mrb_state *mrb, mrb_callinfo *ci, mrb_code *pc) +mrb_get_backtrace(mrb_state *mrb) { mrb_value ary; - mrb_int ciidx = ci - mrb->c->cibase; + mrb_callinfo *ci = mrb->c->ci; + mrb_code *pc = ci->pc; + mrb_int ciidx = ci - mrb->c->cibase - 1; + if (ciidx < 0) ciidx = 0; ary = mrb_ary_new(mrb); output_backtrace(mrb, ciidx, pc, get_backtrace_i, (void*)mrb_ary_ptr(ary)); diff --git a/src/error.c b/src/error.c index 8d0ec67e0..26dc97166 100644 --- a/src/error.c +++ b/src/error.c @@ -431,8 +431,6 @@ mrb_sys_fail(mrb_state *mrb, const char *mesg) } } -mrb_value mrb_get_backtrace(mrb_state*, mrb_value); - void mrb_init_exception(mrb_state *mrb) { @@ -446,7 +444,7 @@ mrb_init_exception(mrb_state *mrb) mrb_define_method(mrb, e, "to_s", exc_to_s, MRB_ARGS_NONE()); mrb_define_method(mrb, e, "message", exc_message, MRB_ARGS_NONE()); mrb_define_method(mrb, e, "inspect", exc_inspect, MRB_ARGS_NONE()); - mrb_define_method(mrb, e, "backtrace", mrb_get_backtrace, MRB_ARGS_NONE()); + mrb_define_method(mrb, e, "backtrace", mrb_exc_backtrace, MRB_ARGS_NONE()); mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */ mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */ |
