[macruby-changes] [2682] MacRuby/trunk/variable.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 29 20:12:16 PDT 2009


Revision: 2682
          http://trac.macosforge.org/projects/ruby/changeset/2682
Author:   lsansonetti at apple.com
Date:     2009-09-29 20:12:14 -0700 (Tue, 29 Sep 2009)
Log Message:
-----------
don't use a write barrier in var_setter since it might not work all the time

Modified Paths:
--------------
    MacRuby/trunk/variable.c

Modified: MacRuby/trunk/variable.c
===================================================================
--- MacRuby/trunk/variable.c	2009-09-30 01:55:49 UTC (rev 2681)
+++ MacRuby/trunk/variable.c	2009-09-30 03:12:14 UTC (rev 2682)
@@ -422,7 +422,7 @@
     var->setter = val_setter;
     var->marker = val_marker;
 
-    GC_WB(&var->data, (void*)val);
+    GC_WB(&var->data, val);
 }
 
 static void
@@ -439,7 +439,7 @@
 static void
 val_setter(VALUE val, ID id, void *data, struct global_variable *var)
 {
-    GC_WB(&var->data, (void*)val);
+    GC_WB(&var->data, val);
 }
 
 static void
@@ -453,20 +453,26 @@
 static VALUE
 var_getter(ID id, VALUE *var)
 {
-    if (!var) return Qnil;
+    if (var == NULL) {
+	return Qnil;
+    }
     return *var;
 }
 
 static void
 var_setter(VALUE val, ID id, VALUE *var)
 {
-    GC_WB(var, val);
+    if (*var != val) {
+	GC_RELEASE(*var);
+	*var = val;
+	GC_RETAIN(*var);
+    }
 }
 
 static void
 var_marker(VALUE *var)
 {
-    if (var) {
+    if (var != NULL) {
 	rb_gc_mark_maybe(*var);
     }
 }
@@ -517,27 +523,19 @@
 }
 
 void
-rb_define_hooked_variable(
-    const char *name,
-    VALUE *var,
-    VALUE (*getter)(ANYARGS),
-    void  (*setter)(ANYARGS))
+rb_define_hooked_variable(const char *name, VALUE *var,
+	VALUE (*getter)(ANYARGS), void  (*setter)(ANYARGS))
 {
-    struct global_variable *gvar;
-    ID id;
-    VALUE tmp;
-    
-    if (var)
-        tmp = *var;
-
-    id = global_id(name);
-    gvar = rb_global_entry(id)->var;
-    gvar->data = (void*)var;
-    gvar->getter = getter?getter:var_getter;
-    gvar->setter = setter?setter:var_setter;
+    ID id = global_id(name);
+    struct global_variable *gvar = rb_global_entry(id)->var;
+    gvar->data = (void *)var;
+    gvar->getter = getter != NULL ? getter : var_getter;
+    gvar->setter = setter != NULL ? setter : var_setter;
     gvar->marker = var_marker;
 
-    GC_ROOT(var);
+    if (var != NULL) {
+	GC_RETAIN(*var);
+    }
 }
 
 void
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090929/23596ee1/attachment.html>


More information about the macruby-changes mailing list