From 810d13dacdd4cdf6ce55de85266f3ac26da520ef Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 3 Feb 2021 09:41:22 +0900 Subject: Move `MRB_TRY` part of `mrb_close` to `src/error.c`; ref 6cc52b3 We don't want to increase number of files that should be compiled by C++ compiler when `enable_cxx_exception` is turned on. --- src/error.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index d2f1c27ac..256f9169d 100644 --- a/src/error.c +++ b/src/error.c @@ -591,6 +591,28 @@ mrb_core_init_abort(mrb_state *mrb) exc_throw(mrb, mrb_nil_value()); } +void +mrb_protect_atexit(mrb_state *mrb) +{ + if (mrb->atexit_stack_len > 0) { + struct mrb_jmpbuf *prev_jmp = mrb->jmp; + struct mrb_jmpbuf c_jmp; + for (int i = mrb->atexit_stack_len; i > 0; --i) { + MRB_TRY(&c_jmp) { + mrb->jmp = &c_jmp; + mrb->atexit_stack[i - 1](mrb); + mrb->jmp = prev_jmp; + } MRB_CATCH(&c_jmp) { + /* ignore atexit errors */ + } MRB_END_EXC(&c_jmp); + } +#ifndef MRB_FIXED_STATE_ATEXIT_STACK + mrb_free(mrb, mrb->atexit_stack); +#endif + mrb->jmp = prev_jmp; + } +} + mrb_noreturn void mrb_raise_nomemory(mrb_state *mrb) { -- cgit v1.2.3