vala r1850 - in trunk: . gobject vapi



Author: juergbi
Date: Fri Oct 17 12:54:46 2008
New Revision: 1850
URL: http://svn.gnome.org/viewvc/vala?rev=1850&view=rev

Log:
2008-10-17  JÃrg Billeter  <j bitron ch>

	* gobject/valaccodeclassbinding.vala:
	* gobject/valaccodegenerator.vala:
	* vapi/glib-2.0.vapi:

	Fix leaks in non-GObject classes,
	based on patch by Andrea Del Signore, fixes bug 554844


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodeclassbinding.vala
   trunk/gobject/valaccodegenerator.vala
   trunk/vapi/glib-2.0.vapi

Modified: trunk/gobject/valaccodeclassbinding.vala
==============================================================================
--- trunk/gobject/valaccodeclassbinding.vala	(original)
+++ trunk/gobject/valaccodeclassbinding.vala	Fri Oct 17 12:54:46 2008
@@ -196,10 +196,8 @@
 			
 			add_instance_init_function (cl);
 
-			if (is_gobject) {
-				if (cl.get_fields ().size > 0 || cl.destructor != null) {
-					add_finalize_function (cl);
-				}
+			if (!cl.is_compact && (cl.get_fields ().size > 0 || cl.destructor != null || cl.is_fundamental ())) {
+				add_finalize_function (cl);
 			}
 
 			var type_fun = new ClassRegisterFunction (cl, codegen);
@@ -256,6 +254,15 @@
 				var destroy_block = new CCodeBlock ();
 				var get_class = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS".printf (cl.get_upper_case_cname (null))));
 				get_class.add_argument (new CCodeIdentifier ("self"));
+
+				// finalize class
+				var ccast = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS".printf (cl.get_upper_case_cname (null))));
+				ccast.add_argument (new CCodeIdentifier ("self"));
+				ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (ccast, "finalize"));
+				ccall.add_argument (new CCodeIdentifier ("self"));
+				destroy_block.add_statement (new CCodeExpressionStatement (ccall));
+
+				// free type instance
 				var free = new CCodeFunctionCall (new CCodeIdentifier ("g_type_free_instance"));
 				free.add_argument (new CCodeCastExpression (new CCodeIdentifier ("self"), "GTypeInstance *"));
 				destroy_block.add_statement (new CCodeExpressionStatement (free));
@@ -683,6 +690,20 @@
 		var parent_assignment = new CCodeAssignment (new CCodeIdentifier ("%s_parent_class".printf (cl.get_lower_case_cname (null))), ccall);
 		init_block.add_statement (new CCodeExpressionStatement (parent_assignment));
 		
+
+		if (!cl.is_compact && !cl.is_static && !cl.is_subtype_of (codegen.gobject_type) && (cl.get_fields ().size > 0 || cl.destructor != null || cl.is_fundamental ())) {
+			// set finalize function
+			var fundamental_class = cl;
+			while (fundamental_class.base_class != null) {
+				fundamental_class = fundamental_class.base_class;
+			}
+
+			ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (fundamental_class.get_upper_case_cname (null))));
+			ccall.add_argument (new CCodeIdentifier ("klass"));
+			var finalize_assignment = new CCodeAssignment (new CCodeMemberAccess.pointer (ccall, "finalize"), new CCodeIdentifier (cl.get_lower_case_cprefix () + "finalize"));
+			init_block.add_statement (new CCodeExpressionStatement (finalize_assignment));
+		}
+
 		/* add struct for private fields */
 		if (cl.has_private_fields || cl.get_type_parameters ().size > 0) {
 			ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_add_private"));
@@ -1039,9 +1060,14 @@
 	private void add_finalize_function (Class cl) {
 		var function = new CCodeFunction ("%s_finalize".printf (cl.get_lower_case_cname (null)), "void");
 		function.modifiers = CCodeModifiers.STATIC;
-		
-		function.add_parameter (new CCodeFormalParameter ("obj", "GObject *"));
-		
+
+		var fundamental_class = cl;
+		while (fundamental_class.base_class != null) {
+			fundamental_class = fundamental_class.base_class;
+		}
+
+		function.add_parameter (new CCodeFormalParameter ("obj", fundamental_class.get_cname () + "*"));
+
 		codegen.source_type_member_declaration.append (function.copy ());
 
 
@@ -1061,11 +1087,13 @@
 		cblock.add_statement (codegen.instance_finalize_fragment);
 
 		// chain up to finalize function of the base class
-		var ccast = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_CLASS"));
-		ccast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (cl.get_lower_case_cname (null))));
-		ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (ccast, "finalize"));
-		ccall.add_argument (new CCodeIdentifier ("obj"));
-		cblock.add_statement (new CCodeExpressionStatement (ccall));
+		if (cl.base_class != null) {
+			var ccast = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (fundamental_class.get_upper_case_cname ())));
+			ccast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (cl.get_lower_case_cname (null))));
+			ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (ccast, "finalize"));
+			ccall.add_argument (new CCodeIdentifier ("obj"));
+			cblock.add_statement (new CCodeExpressionStatement (ccall));
+		}
 
 
 		function.block = cblock;

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Fri Oct 17 12:54:46 2008
@@ -1646,7 +1646,7 @@
 
 		var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cvar, new CCodeConstant ("NULL"));
 		if (type.type_parameter != null) {
-			if (!(current_type_symbol is Class) || !current_class.is_subtype_of (gobject_type)) {
+			if (!(current_type_symbol is Class) || current_class.is_compact) {
 				return new CCodeConstant ("NULL");
 			}
 

Modified: trunk/vapi/glib-2.0.vapi
==============================================================================
--- trunk/vapi/glib-2.0.vapi	(original)
+++ trunk/vapi/glib-2.0.vapi	Fri Oct 17 12:54:46 2008
@@ -850,11 +850,6 @@
 		public uint instance_size;
 	}
 
-	// deprecated
-	[CCode (has_type_id = true)]
-	public class TypeInstance {
-	}
-
 	[Compact]
 	[CCode (ref_function = "g_type_class_ref", unref_function = "g_type_class_unref")]
 	public class TypeClass {
@@ -949,7 +944,7 @@
 	public static delegate void WeakNotify (void *data, Object object);
 
 	[CCode (ref_function = "g_object_ref", unref_function = "g_object_unref", marshaller_type_name = "OBJECT", get_value_function = "g_value_get_object", set_value_function = "g_value_set_object", param_spec_function = "g_param_spec_object", cheader_filename = "glib-object.h")]
-	public class Object : TypeInstance {
+	public class Object {
 		public uint ref_count;
 
 		public static Object @new (Type type, ...);



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