[vala] codegen: Fix freeing on assignment to fields of generic type
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Fix freeing on assignment to fields of generic type
- Date: Sun, 27 Mar 2011 18:29:23 +0000 (UTC)
commit cf1e6dd2c1af64ddfe1b2332355c9a437f8c6ddf
Author: Jürg Billeter <j bitron ch>
Date: Sun Mar 27 20:26:37 2011 +0200
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 3f6dd65..1bc79f2 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 4ac24db..ecc80d7 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 285c09a..7c14732 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 ()));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]