Watson1978
5/21/2011 - 2:54 PM

MacRuby : patch

MacRuby : patch

diff --git a/dispatcher.cpp b/dispatcher.cpp
index b04f1e8..7fbbb22 100644
--- a/dispatcher.cpp
+++ b/dispatcher.cpp
@@ -1084,7 +1084,7 @@ dup_block(rb_vm_block_t *src_b)
     while (src_l != NULL) {
 	GC_WB(new_l, xmalloc(sizeof(rb_vm_local_t)));
 	(*new_l)->name = src_l->name;
-	(*new_l)->value = src_l->value;
+	GC_WB(&(*new_l)->value, src_l->value);
 
 	new_l = &(*new_l)->next;
 	src_l = src_l->next;
@@ -1318,7 +1318,7 @@ rb_vm_yield_under(VALUE klass, VALUE self, int argc, const VALUE *argv)
     vm->pop_current_block();
 
     VALUE old_self = b->self;
-    b->self = self;
+    GC_WB(&b->self, self);
     VALUE old_class = b->klass;
     b->klass = klass;
     GC_WB(&b->outer, vm->create_outer((Class)klass, b->outer, true));
@@ -1337,7 +1337,7 @@ rb_vm_yield_under(VALUE klass, VALUE self, int argc, const VALUE *argv)
 	}
 	~Finally() {
 	    GC_WB(&b->outer, b->outer->outer);
-	    b->self = old_self;
+	    GC_WB(&b->self, old_self);
 	    b->klass = old_class;
 	    vm->add_current_block(b);
 	}
@@ -1418,13 +1418,13 @@ rb_vm_prepare_block(void *function, int flags, VALUE self, rb_vm_arity_t arity,
 		GET_CORE()->unlock();
 #endif
 	    }
-	    b->userdata = (VALUE)function;
+	    GC_WB(&b->userdata, (VALUE)function);
 	}
 	b->arity = arity;
 	b->flags = flags;
 	b->dvars_size = dvars_size;
 	b->parent_var_uses = NULL;
-	b->parent_block = NULL;
+	GC_WB(&b->parent_block, NULL);
     }
     else {
 	assert(b->dvars_size == dvars_size);
@@ -1456,7 +1456,7 @@ rb_vm_prepare_block(void *function, int flags, VALUE self, rb_vm_arity_t arity,
 	for (int i = 0; i < lvars_size; ++i) {
 	    assert(l != NULL);
 	    l->name = va_arg(ar, ID);
-	    l->value = va_arg(ar, VALUE *);
+	    GC_WB(&l->value, va_arg(ar, VALUE *));
 	    l = l->next;
 	}
     }
diff --git a/vm.cpp b/vm.cpp
index ffcb22d..38b0093 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -502,6 +502,7 @@ RoxorVM::~RoxorVM(void)
     GC_RELEASE(broken_with);
     GC_RELEASE(last_status);
     GC_RELEASE(errinfo);
+    GC_RELEASE(outer_stack);
 
     free(mcache);
     mcache = NULL;
@@ -1416,11 +1417,11 @@ rb_vm_const_is_defined(ID path)
 
 #define GET_OUTER_STACK(dest, src) \
     rb_vm_outer_t *dest = (src); \
-    GC_RETAIN(dest); \
     struct ReleaseOuterStack { \
 	rb_vm_outer_t *outer_stack; \
 	ReleaseOuterStack(rb_vm_outer_t *_outer_stack) { \
 	    outer_stack = _outer_stack; \
+	    GC_RETAIN(outer_stack); \
 	} \
 	~ReleaseOuterStack() { \
 	    GC_RELEASE(outer_stack); \
@@ -3332,7 +3333,7 @@ rb_vm_keep_vars(rb_vm_var_uses *uses, int lvars_size, ...)
 		}
 
 		// the parent pointers can't be used anymore
-		block->parent_block = NULL;
+		GC_WB(&block->parent_block, NULL);
 		block->parent_var_uses = NULL;
 
 		locals_to_replace = block->locals;
@@ -3363,7 +3364,7 @@ push_local(rb_vm_local_t **l, ID name, VALUE *value)
 {
     GC_WB(l, xmalloc(sizeof(rb_vm_local_t)));
     (*l)->name = name;
-    (*l)->value = value;
+    GC_WB(&(*l)->value, value);
     (*l)->next = NULL;
     return &(*l)->next;
 }
@@ -3498,7 +3499,7 @@ rb_vm_create_block_from_method(rb_vm_method_t *method)
     b->flags = VM_BLOCK_PROC | VM_BLOCK_METHOD;
     b->locals = NULL;
     b->parent_var_uses = NULL;
-    b->parent_block = NULL;
+    GC_WB(&b->parent_block, NULL);
     b->dvars_size = 0;
 
     return b;
@@ -5619,8 +5620,10 @@ rb_vm_dln_load(void (*init_fct)(void), IMP __mrep__)
 	}
 	~Finally() { 
 	    vm->pop_outer();
-	    vm->replace_outer_stack(old_outer_stack);
-	    GC_RELEASE(old_outer_stack);
+	    if (old_outer_stack != NULL) {
+		vm->replace_outer_stack(old_outer_stack);
+		GC_RELEASE(old_outer_stack);
+	    }
 	    vm->set_current_class(old_class);
 	}
     } finalizer(vm);
@@ -5665,8 +5668,10 @@ rb_vm_load(const char *fname_str, int wrap)
 	}
 	~Finally() { 
 	    vm->pop_outer();
-	    vm->replace_outer_stack(old_outer_stack);
-	    GC_RELEASE(old_outer_stack);
+	    if (old_outer_stack != NULL) {
+		vm->replace_outer_stack(old_outer_stack);
+		GC_RELEASE(old_outer_stack);
+	    }
 	    vm->set_current_class(old_class);
 	}
     } finalizer(vm);