vala r1179 - in trunk: . gobject vala



Author: juergbi
Date: Mon Apr  7 20:50:22 2008
New Revision: 1179
URL: http://svn.gnome.org/viewvc/vala?rev=1179&view=rev

Log:
2008-04-07  Juerg Billeter  <j bitron ch>

	* vala/valamemorymanager.vala, vala/valasemanticanalyzer.vala,
	  gobject/valaccodegenerator.vala: fix memory management when
	  mixing pointers and strong references, fixes bug 522110


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodegenerator.vala
   trunk/vala/valamemorymanager.vala
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Mon Apr  7 20:50:22 2008
@@ -1220,6 +1220,9 @@
 		} else if (type is ArrayType) {
 			Report.error (type.source_reference, "internal error: duplicating %s instances not yet supported".printf (type.to_string ()));
 			return null;
+		} else if (type is PointerType) {
+			var pointer_type = (PointerType) type;
+			return get_dup_func_expression (pointer_type.base_type);
 		} else {
 			return new CCodeConstant ("NULL");
 		}

Modified: trunk/vala/valamemorymanager.vala
==============================================================================
--- trunk/vala/valamemorymanager.vala	(original)
+++ trunk/vala/valamemorymanager.vala	Mon Apr  7 20:50:22 2008
@@ -41,18 +41,17 @@
 	}
 	
 	private void visit_possibly_leaked_expression (Expression! expr) {
-		if (expr.static_type != null &&
-		    expr.static_type.is_reference_type_or_type_parameter () &&
-		    expr.static_type.transfers_ownership) {
+		if (expr.static_type != null
+		    && expr.static_type.transfers_ownership) {
 			/* mark reference as leaked */
 			expr.ref_leaked = true;
 		}
 	}
 
 	private void visit_possibly_missing_copy_expression (Expression! expr) {
-		if (expr.static_type != null &&
-		    expr.static_type.is_reference_type_or_type_parameter () &&
-		    !expr.static_type.transfers_ownership) {
+		if (expr.static_type != null
+		    && !expr.static_type.transfers_ownership
+		    && !(expr.static_type is NullType)) {
 			/* mark reference as missing */
 			expr.ref_missing = true;
 		}
@@ -216,7 +215,11 @@
 	public override void visit_array_creation_expression (ArrayCreationExpression! e) {
 		if (e.initializer_list != null) {
 			foreach (Expression init in e.initializer_list.get_initializers ()) {
-				visit_possibly_missing_copy_expression (init);
+				if (init.static_type.is_reference_type_or_type_parameter ()) {
+					visit_possibly_missing_copy_expression (init);
+				} else {
+					visit_possibly_leaked_expression (init);
+				}
 			}
 		}
 	}

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Mon Apr  7 20:50:22 2008
@@ -2500,7 +2500,8 @@
 			return;
 		}
 
-		if (!expr.inner.static_type.takes_ownership) {
+		if (!expr.inner.static_type.takes_ownership
+		    && !(expr.inner.static_type is PointerType)) {
 			expr.error = true;
 			Report.error (expr.source_reference, "No reference to be transferred");
 			return;



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