[macruby-changes] [2575] MacRuby/trunk/ext/libyaml/rubyext.c

source_changes at macosforge.org source_changes at macosforge.org
Sat Sep 19 03:24:03 PDT 2009


Revision: 2575
          http://trac.macosforge.org/projects/ruby/changeset/2575
Author:   vincent.isambart at gmail.com
Date:     2009-09-19 03:24:00 -0700 (Sat, 19 Sep 2009)
Log Message:
-----------
fixed the reference count underflow in YAML

Note: From what I saw, in the only case where interpret_value was
called with collect = true, result was already made collectable so
CFRelease should not be called on it.

I do not know the GC very well so do not hesitate to revert if
I made a mistake.

Modified Paths:
--------------
    MacRuby/trunk/ext/libyaml/rubyext.c

Modified: MacRuby/trunk/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/trunk/ext/libyaml/rubyext.c	2009-09-19 08:39:31 UTC (rev 2574)
+++ MacRuby/trunk/ext/libyaml/rubyext.c	2009-09-19 10:24:00 UTC (rev 2575)
@@ -14,6 +14,7 @@
 #include "id.h"
 #include "vm.h"
 #include "yaml.h"
+#include <unistd.h>
 
 // Ideas to speed this up:
 // none as of yet. need to figure out how to get Shark to link against this .bundle
@@ -316,29 +317,20 @@
 }
 
 static VALUE
-interpret_value(rb_yaml_parser_t *parser, VALUE result, VALUE handler,
-	bool collect)
+interpret_value(rb_yaml_parser_t *parser, VALUE result, VALUE handler)
 {
     if (NIL_P(handler)) {
-	return collect ? (VALUE)CFMakeCollectable((CFTypeRef)result) : result;
+	return result;
     }
     if (rb_vm_respond_to(handler, sel_call, 0)) {
-	VALUE r = rb_vm_call_with_cache(call_cache, handler, sel_call, 1,
+	return rb_vm_call_with_cache(call_cache, handler, sel_call, 1,
 		&result);
-	if (collect) {
-	    CFRelease((CFTypeRef)result);
-	}
-	return r;
     }
     else if (rb_vm_respond_to(handler, sel_yaml_new, 0)) {
-	VALUE r = rb_vm_call_with_cache(yaml_new_cache, handler, sel_yaml_new,
+	return rb_vm_call_with_cache(yaml_new_cache, handler, sel_yaml_new,
 		1, &result);
-	if (collect) {
-	    CFRelease((CFTypeRef)result);
-	}
-	return r;
     }
-    return collect ? (VALUE)CFMakeCollectable((CFTypeRef)result) : result;
+    return result;
 }
 
 static inline bool
@@ -403,7 +395,7 @@
 	    parser->event.data.scalar.length,
 	    kCFStringEncodingUTF8, true);
     CFMakeCollectable((CFTypeRef)scalarval);
-    return interpret_value(parser, scalarval, handler, true);
+    return interpret_value(parser, scalarval, handler);
 }
 
 static VALUE
@@ -417,7 +409,7 @@
     while ((node = get_node(parser)) != Qundef) {
 	rb_ary_push(arr, node);
     }
-    return interpret_value(parser, arr, handler, false);
+    return interpret_value(parser, arr, handler);
 }
 
 static VALUE
@@ -435,7 +427,7 @@
 	}
 	rb_hash_aset(hash, key_node, value_node);
     }
-    return interpret_value(parser, hash, handler, false);
+    return interpret_value(parser, hash, handler);
 }
 
 static inline VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090919/7fb7edce/attachment.html>


More information about the macruby-changes mailing list