1 #include <ruby/ruby.h>
2 #include <ruby/vm.h>
3 
4 static void
do_nothing(ruby_vm_t * vm)5 do_nothing(ruby_vm_t *vm)
6 {
7 }
8 
9 static void
print_begin(ruby_vm_t * vm)10 print_begin(ruby_vm_t *vm)
11 {
12     printf("begin\n");
13 }
14 
15 static void
print_end(ruby_vm_t * vm)16 print_end(ruby_vm_t *vm)
17 {
18     printf("end\n");
19 }
20 
21 static VALUE
register_at_exit(VALUE self,VALUE t)22 register_at_exit(VALUE self, VALUE t)
23 {
24     switch (t) {
25       case Qtrue:
26 	ruby_vm_at_exit(print_begin);
27 	break;
28       case Qfalse:
29 	ruby_vm_at_exit(print_end);
30 	break;
31       default:
32 	ruby_vm_at_exit(do_nothing);
33 	break;
34     }
35     return self;
36 }
37 
38 void
Init_at_exit(void)39 Init_at_exit(void)
40 {
41     VALUE m = rb_define_module("Bug");
42     VALUE c = rb_define_class_under(m, "VM", rb_cObject);
43     rb_define_singleton_method(c, "register_at_exit", register_at_exit, 1);
44 }
45