diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-02 11:06:32 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-02 11:06:32 +0000 |
commit | 51da92ea1216e9d5139d03308618def2f9d4746a (patch) | |
tree | 88bd04102359d7ed638dd1b54d30aa980fa1bbf9 /eval.c | |
parent | cf39e78e1f2248dfda6ba602ed3d73cd201fdb88 (diff) | |
download | ruby-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 'eval.c')
-rw-r--r-- | eval.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -129,6 +129,9 @@ ruby_cleanup(volatile int ex) int nerr; void rb_threadptr_interrupt(rb_thread_t *th); void rb_threadptr_check_signal(rb_thread_t *mth); + int i; + rb_vm_t *vm = GET_VM(); + VALUE ary = (VALUE)&vm->at_exit; rb_threadptr_interrupt(th); rb_threadptr_check_signal(th); @@ -148,6 +151,13 @@ ruby_cleanup(volatile int ex) } POP_TAG(); + /* at_exit functions called here; any other place more apropriate + * for this purpose? let me know if any. */ + for (i=0; i<RARRAY_LEN(ary); i++) { + ((void(*)(rb_vm_t*))RARRAY_PTR(ary)[i])(vm); + } + rb_ary_clear(ary); + errs[0] = th->errinfo; PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { |