vala r2279 - in trunk: . gobject vala



Author: juergbi
Date: Tue Jan  6 22:59:20 2009
New Revision: 2279
URL: http://svn.gnome.org/viewvc/vala?rev=2279&view=rev

Log:
2009-01-06  JÃrg Billeter  <j bitron ch>

	* vala/valaclass.vala:
	* gobject/valaccodebasemodule.vala:

	Support [CCode (ref_function_void = true)] attribute for bindings,
	based on patch by Andreas Brauchli, fixes bug 566078


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodebasemodule.vala
   trunk/vala/valaclass.vala

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Tue Jan  6 22:59:20 2009
@@ -2460,6 +2460,15 @@
 		return true;
 	}
 
+	bool is_ref_function_void (DataType type) {
+		var cl = type.data_type as Class;
+		if (cl != null && cl.ref_function_void) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
 	public CCodeExpression? get_ref_cexpression (DataType expression_type, CCodeExpression cexpr, Expression? expr, CodeNode node) {
 		if (expression_type is ValueType && !expression_type.nullable) {
 			// normal value type, no null check
@@ -2521,7 +2530,8 @@
 
 		var ccall = new CCodeFunctionCall (dupexpr);
 
-		if (!(expression_type is ArrayType) && expr != null && expr.is_non_null ()) {
+		if (!(expression_type is ArrayType) && expr != null && expr.is_non_null ()
+		    && !is_ref_function_void (expression_type)) {
 			// expression is non-null
 			ccall.add_argument ((CCodeExpression) expr.ccodenode);
 			
@@ -2582,6 +2592,12 @@
 			}
 			ccomma.append_expression (new CCodeConditionalExpression (cisnull, cifnull, ccall));
 
+			// repeat temp variable at the end of the comma expression
+			// if the ref function returns void
+			if (is_ref_function_void (expression_type)) {
+				ccomma.append_expression (ctemp);
+			}
+
 			return ccomma;
 		}
 	}

Modified: trunk/vala/valaclass.vala
==============================================================================
--- trunk/vala/valaclass.vala	(original)
+++ trunk/vala/valaclass.vala	Tue Jan  6 22:59:20 2009
@@ -71,6 +71,12 @@
 	}
 
 	/**
+	 * Specifies wheather the ref function returns void instead of the
+	 * object.
+	 */
+	public bool ref_function_void { get; set; }
+
+	/**
 	 * The name of the function to use to check whether a value is an instance of
 	 * this class. If this is null then the default type check function should be 
 	 * used instead.
@@ -575,6 +581,9 @@
 		if (a.has_argument ("ref_function")) {
 			set_ref_function (a.get_string ("ref_function"));
 		}
+		if (a.has_argument ("ref_function_void")) {
+			this.ref_function_void = a.get_bool ("ref_function_void");
+		}
 		if (a.has_argument ("unref_function")) {
 			set_unref_function (a.get_string ("unref_function"));
 		}



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