summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-02 11:06:32 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-02 11:06:32 +0000
commit51da92ea1216e9d5139d03308618def2f9d4746a (patch)
tree88bd04102359d7ed638dd1b54d30aa980fa1bbf9 /vm.c
parentcf39e78e1f2248dfda6ba602ed3d73cd201fdb88 (diff)
downloadruby-51da92ea1216e9d5139d03308618def2f9d4746a.tar.gz
* vm.c (ruby_vm_at_exit): new API. This enables extension libs to
hook a VM termination. Right now, because the VM we have is process global, most extensions do not deallocate resources and leave them to Operating System's reaping userland processes. But in a future we plan to have multiple VMs to run simultaneously in a single process (MVM project). At that stage we can no longer rely on OSes and have to manage every resources to be reclaimed properly. So it is. For a forward-compatibility reason this API is introduced now, encouraging you to be as gentle as you can for your resources; that is, tidy up your room. * include/ruby/vm.h: ditto. * vm_core.h (rb_vm_struct): new field. * vm.c (vm_init2): initialize above new field. * eval.c (ruby_cleanup): trigger those hooks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/vm.c b/vm.c
index 2a25cb1f37..aca61c6906 100644
--- a/vm.c
+++ b/vm.c
@@ -173,6 +173,14 @@ vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
return 0;
}
+/* at exit */
+
+void
+ruby_vm_at_exit(void (*func)(rb_vm_t *))
+{
+ rb_ary_push((VALUE)&GET_VM()->at_exit, (VALUE)func);
+}
+
/* Env */
/*
@@ -1572,6 +1580,8 @@ vm_init2(rb_vm_t *vm)
{
MEMZERO(vm, rb_vm_t, 1);
vm->src_encoding_index = -1;
+ vm->at_exit.basic.flags = (T_ARRAY | RARRAY_EMBED_FLAG) & ~RARRAY_EMBED_LEN_MASK; /* len set 0 */
+ vm->at_exit.basic.klass = 0;
}
/* Thread */