summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/vm.c b/vm.c
index 5db91dd6ae8..9528040a9e3 100644
--- a/vm.c
+++ b/vm.c
@@ -181,6 +181,19 @@ ruby_vm_at_exit(void (*func)(rb_vm_t *))
rb_ary_push((VALUE)&GET_VM()->at_exit, (VALUE)func);
}
+static void
+ruby_vm_run_at_exit_hooks(rb_vm_t *vm)
+{
+ VALUE hook = (VALUE)&vm->at_exit;
+
+ while (RARRAY_LEN(hook) > 0) {
+ typedef void rb_vm_at_exit_func(rb_vm_t*);
+ rb_vm_at_exit_func *func = (rb_vm_at_exit_func*)rb_ary_pop(hook);
+ (*func)(vm);
+ }
+ rb_ary_free(hook);
+}
+
/* Env */
/*
@@ -1550,6 +1563,7 @@ ruby_vm_destruct(rb_vm_t *vm)
rb_objspace_free(objspace);
}
#endif
+ ruby_vm_run_at_exit_hooks(vm);
rb_vm_gvl_destroy(vm);
ruby_xfree(vm);
ruby_current_vm = 0;