diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-18 07:29:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-18 07:29:17 +0000 |
commit | d36c76dc71b47b201707185b8a0b4264e83de205 (patch) | |
tree | df6b3edc1d6715dd11be75675f5ec55c54d3fa11 /vm.c | |
parent | 868684096079f3e786df517714fe6d795c4647b6 (diff) |
* common.mk (eval.o): needs vm.h.
* eval.c (ruby_cleanup): destruct current VM before exit.
* gc.c (rb_objspace_free): free object space.
* vm.c (ruby_vm_destruct): destruct and free VM struct.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -25,6 +25,8 @@ #include "vm_method.c" #include "vm_eval.c" +#include <assert.h> + #define BUFSIZE 0x100 #define PROCDEBUG 0 @@ -41,6 +43,8 @@ char ruby_vm_redefined_flag[BOP_LAST_]; rb_thread_t *ruby_current_thread = 0; rb_vm_t *ruby_current_vm = 0; +static void thread_free(void *ptr); + VALUE rb_insns_name_array(void); void vm_analysis_operand(int insn, int n, VALUE op); @@ -1464,21 +1468,36 @@ rb_vm_mark(void *ptr) RUBY_MARK_LEAVE("vm"); } -static void -vm_free(void *ptr) +#define vm_free 0 + +int +ruby_vm_destruct(rb_vm_t *vm) { RUBY_FREE_ENTER("vm"); - if (ptr) { - rb_vm_t *vmobj = ptr; - - st_free_table(vmobj->living_threads); - vmobj->living_threads = 0; - /* TODO: MultiVM Instance */ - /* VM object should not be cleaned by GC */ - /* ruby_xfree(ptr); */ - /* ruby_current_vm = 0; */ + if (vm) { + rb_thread_t *th = vm->main_thread; +#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE + struct rb_objspace *objspace = vm->objspace; +#endif + rb_gc_force_recycle(vm->self); + vm->main_thread = 0; + if (th) { + thread_free(th); + } + if (vm->living_threads) { + st_free_table(vm->living_threads); + vm->living_threads = 0; + } + ruby_xfree(vm); + ruby_current_vm = 0; +#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE + if (objspace) { + rb_objspace_free(objspace); + } +#endif } RUBY_FREE_LEAVE("vm"); + return 0; } static size_t |