mruby-exit.c: make exit() to raise SystemExit exception.

Now it allows error handlers to work, unlike `exit!`.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-09-21 22:33:32 +09:00
parent 11504318b8
commit 07470eb538
4 changed files with 61 additions and 24 deletions
+8
View File
@@ -21,6 +21,14 @@ struct RException {
struct RObject *backtrace; // NULL, RArray or RData
};
/* error that should terminate execution */
#define MRB_EXC_EXIT 65536
#define MRB_EXC_EXIT_P(e) ((e)->flags & MRB_EXC_EXIT)
/* retrieve status value from exc; need <mruby/variable.h> and <mruby/presym.h> */
#define MRB_EXC_EXIT_STATUS(mrb,e) ((int)mrb_as_int((mrb),mrb_obj_iv_get((mrb),(e),MRB_SYM(status))))
/* exit with SystemExit status */
#define MRB_EXC_CHECK_EXIT(mrb,e) do {if (MRB_EXC_EXIT_P(e)) exit(MRB_EXC_EXIT_STATUS((mrb),(e)));} while (0)
#define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
MRB_API mrb_noreturn void mrb_sys_fail(mrb_state *mrb, const char *mesg);