From 1e90d53dba0eff6ec2babd8292676099308dd4f6 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Thu, 9 Jun 2011 13:37:23 +0200 Subject: [PATCH] codegen: Support owned delegate parameter in set accessor --- codegen/valaccodebasemodule.vala | 15 +++++++++++++++ tests/objects/properties.vala | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 5deaf959d..62a6d4584 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 e66ecbeb3..78f17a7c9 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 () { -- 2.47.2