From cf1e6dd2c1af64ddfe1b2332355c9a437f8c6ddf Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Sun, 27 Mar 2011 20:26:37 +0200 Subject: [PATCH] codegen: Fix freeing on assignment to fields of generic type Fixes bug 645773. --- codegen/valaccodeassignmentmodule.vala | 2 +- codegen/valaccodebasemodule.vala | 2 +- codegen/valaccodememberaccessmodule.vala | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala index 3f6dd65e..1bc79f27 100644 --- a/codegen/valaccodeassignmentmodule.vala +++ b/codegen/valaccodeassignmentmodule.vala @@ -239,7 +239,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule { } public override void store_field (Field field, TargetValue? instance, TargetValue value) { - if (requires_destroy (field.variable_type)) { + if (requires_destroy (get_field_cvalue (field, instance).value_type)) { /* unref old value */ ccode.add_expression (destroy_field (field, instance)); } diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 4ac24db4..ecc80d72 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -2803,7 +2803,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { // logic in this method is temporarily duplicated in destroy_value // apply changes to both methods public virtual CCodeExpression destroy_variable (Variable variable, TargetValue target_lvalue) { - var type = variable.variable_type; + var type = target_lvalue.value_type; var cvar = get_cvalue_ (target_lvalue); if (type is DelegateType) { diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala index 285c09a7..7c14732f 100644 --- a/codegen/valaccodememberaccessmodule.vala +++ b/codegen/valaccodememberaccessmodule.vala @@ -493,10 +493,15 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { /* Returns lvalue access to the given field */ public override TargetValue get_field_cvalue (Field field, TargetValue? instance) { - var result = new GLibValue (field.variable_type.copy ()); + var value_type = field.variable_type.copy (); + if (instance != null) { + value_type = value_type.get_actual_type (instance.value_type, null, field); + } + + var result = new GLibValue (value_type); - var array_type = field.variable_type as ArrayType; - var delegate_type = field.variable_type as DelegateType; + var array_type = result.value_type as ArrayType; + var delegate_type = result.value_type as DelegateType; if (field.binding == MemberBinding.INSTANCE) { CCodeExpression pub_inst = null; @@ -558,12 +563,12 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { if (((TypeSymbol) field.parent_symbol).is_reference_type ()) { result.delegate_target_cvalue = new CCodeMemberAccess.pointer (inst, target_cname); - if (field.variable_type.value_owned) { + if (result.value_type.value_owned) { result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (inst, target_destroy_notify_cname); } } else { result.delegate_target_cvalue = new CCodeMemberAccess (inst, target_cname); - if (field.variable_type.value_owned) { + if (result.value_type.value_owned) { result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess (inst, target_destroy_notify_cname); } } @@ -620,7 +625,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { } } else if (delegate_type != null && delegate_type.delegate_symbol.has_target && !field.no_delegate_target) { result.delegate_target_cvalue = new CCodeIdentifier (get_delegate_target_cname (field.get_cname ())); - if (field.variable_type.value_owned) { + if (result.value_type.value_owned) { result.delegate_target_destroy_notify_cvalue = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (field.get_cname ())); } } -- 2.11.4.GIT