seed r248 - in trunk: libseed tests



Author: racarr
Date: Tue Nov 11 15:28:24 2008
New Revision: 248
URL: http://svn.gnome.org/viewvc/seed?rev=248&view=rev

Log:
Overhaul reference counting a bit and add a reference counting test.


Added:
   trunk/tests/reference-count-new.js   (contents, props changed)
Modified:
   trunk/libseed/seed-engine.c
   trunk/libseed/seed-types.c
   trunk/tests/Makefile.am

Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c	(original)
+++ trunk/libseed/seed-engine.c	Tue Nov 11 15:28:24 2008
@@ -138,10 +138,15 @@
 
     gobject = g_object_newv(type, nparams, params);
 
+    if (g_object_is_floating(gobject))
+	g_object_ref_sink(gobject);
+
     if (!gobject)
-	JSValueMakeNull(eng->context);
+	ret = (JSObjectRef)JSValueMakeNull(eng->context);
 
-    ret = (JSObjectRef) seed_value_from_object(gobject, 0);
+    ret = (JSObjectRef)seed_value_from_object(gobject, exception);
+    
+    g_object_unref(gobject);
 
     g_type_class_unref(oclass);
 
@@ -178,6 +183,20 @@
 }
 
 static JSValueRef
+seed_gobject_ref_count(JSContextRef ctx,
+		    JSObjectRef function,
+		    JSObjectRef this_object,
+		    size_t argumentCount,
+		    const JSValueRef arguments[], JSValueRef * exception)
+{
+    GObject *this;
+
+    this = seed_value_to_object((JSValueRef) this_object, exception);
+
+    return seed_value_from_int(this->ref_count, exception);
+}
+
+static JSValueRef
 seed_gobject_method_invoked(JSContextRef ctx,
 			    JSObjectRef function,
 			    JSObjectRef this_object,
@@ -834,7 +853,8 @@
 }
 
 JSStaticFunction gobject_static_funcs[] = {
-    {"equals", seed_gobject_equals, 0}
+    {"equals", seed_gobject_equals, 0},
+    {"__debug_ref_count", seed_gobject_ref_count, 0}
     ,
     {0, 0, 0}
 };

Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c	(original)
+++ trunk/libseed/seed-types.c	Tue Nov 11 15:28:24 2008
@@ -87,8 +87,7 @@
     {
 	g_assert_not_reached();
     }
-
-    g_object_ref_sink(object);
+    g_object_ref(object);
 
     g_object_set_data(object, "js-ref", (gpointer) js_ref);
 

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	(original)
+++ trunk/tests/Makefile.am	Tue Nov 11 15:28:24 2008
@@ -3,6 +3,7 @@
     compare.js \
     constructor-args.js \
     signal-this.js \
+    reference-count-new.js \
     gtype-typerror.js \
     gtype-signal.js \
     signal-userdata.js \

Added: trunk/tests/reference-count-new.js
==============================================================================
--- (empty file)
+++ trunk/tests/reference-count-new.js	Tue Nov 11 15:28:24 2008
@@ -0,0 +1,20 @@
+#!/usr/local/bin/seed
+// Returns: 0
+// STDIN:
+// STDOUT:1 1\n1 2\n2\.000000\n1\.000000
+// STDERR:
+Seed.import_namespace("Gtk");
+
+Gtk.init(null, null);
+
+w = new Gtk.Window();
+l = new Gtk.Label();
+
+Seed.print(w.__debug_ref_count() +" "+ l.__debug_ref_count());
+w.add(l);
+Seed.print(w.__debug_ref_count() +" "+ l.__debug_ref_count());
+list = w.get_children();
+l2 = list[0]
+Seed.print(l2.__debug_ref_count());
+w.remove(l);
+Seed.print(l.__debug_ref_count());



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]