[vala] codegen: Support owned delegate parameter in set accessor



commit 1e90d53dba0eff6ec2babd8292676099308dd4f6
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Jun 9 13:37:23 2011 +0200

    codegen: Support owned delegate parameter in set accessor

 codegen/valaccodebasemodule.vala |   15 +++++++++++++++
 tests/objects/properties.vala    |    6 ++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5deaf95..62a6d45 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1343,6 +1343,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			}
 		} else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
 			function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
+			if (!acc.readable && acc.value_type.value_owned) {
+				function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), "GDestroyNotify"));
+			}
 		}
 
 		if (prop.is_private_symbol () || (!acc.readable && !acc.writable) || acc.access == SymbolAccessibility.PRIVATE) {
@@ -1439,6 +1442,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				}
 			} else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
 				function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
+				if (!acc.readable && acc.value_type.value_owned) {
+					function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), "GDestroyNotify"));
+				}
 			}
 
 			if (prop.is_private_symbol () || !(acc.readable || acc.writable) || acc.access == SymbolAccessibility.PRIVATE) {
@@ -1494,6 +1500,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 					}
 				} else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
 					vcall.add_argument (new CCodeIdentifier (get_delegate_target_cname ("value")));
+					if (!acc.readable && acc.value_type.value_owned) {
+						vcall.add_argument (new CCodeIdentifier (get_delegate_target_destroy_notify_cname ("value")));
+					}
 				}
 
 				ccode.add_expression (vcall);
@@ -1556,6 +1565,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				}
 			} else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
 				function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
+				if (!acc.readable && acc.value_type.value_owned) {
+					function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), "GDestroyNotify"));
+				}
 			}
 
 			if (!is_virtual) {
@@ -5385,6 +5397,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			var delegate_type = (DelegateType) prop.property_type;
 			if (delegate_type.delegate_symbol.has_target) {
 				ccall.add_argument (get_delegate_target_cvalue (value));
+				if (delegate_type.value_owned) {
+					ccall.add_argument (get_delegate_target_destroy_notify_cvalue (value));
+				}
 			}
 		}
 
diff --git a/tests/objects/properties.vala b/tests/objects/properties.vala
index e66ecbe..78f17a7 100644
--- a/tests/objects/properties.vala
+++ b/tests/objects/properties.vala
@@ -1,8 +1,12 @@
 using GLib;
 
+public delegate void Delegate ();
+
 public class Sample : Object {
 	private string automatic { get; set; }
 
+	public Delegate deleg { get; owned set; }
+
 	private string _name;
 	public string name {
 		get { return _name; }
@@ -40,6 +44,8 @@ public class Sample : Object {
 		stdout.printf("name: %s\n", name);
 		stdout.printf("read_only: %s\n", read_only);
 		stdout.printf("automatic: %s\n", automatic);
+
+		this.deleg = null;
         }
 
 	public static int main () {



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