Merge pull request #6273 from dearblue/closing

Improvements to `mrb_protect_atexit()`
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-05-25 16:48:56 +09:00
committed by GitHub
+8 -3
View File
@@ -589,19 +589,24 @@ 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) {
int i = mrb->atexit_stack_len;
while (i > 0) {
MRB_TRY(&c_jmp) {
mrb->jmp = &c_jmp;
mrb->atexit_stack[i - 1](mrb);
do {
mrb->atexit_stack[--i](mrb);
mrb_gc_arena_restore(mrb, 0);
} while (i > 0);
mrb->jmp = prev_jmp;
} MRB_CATCH(&c_jmp) {
mrb->jmp = prev_jmp;
/* ignore atexit errors */
mrb_gc_arena_restore(mrb, 0);
} MRB_END_EXC(&c_jmp);
}
#ifndef MRB_FIXED_STATE_ATEXIT_STACK
mrb_free(mrb, mrb->atexit_stack);
#endif
mrb->jmp = prev_jmp;
}
}