From: Luca Bruno Date: Sun, 6 Oct 2013 19:06:46 +0000 (+0200) Subject: Set parent_node and always copy datatype when assigned to code nodes. X-Git-Tag: 0.22.1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a09c9e93af0d64b9331c274de573465fe070b722;p=thirdparty%2Fvala.git Set parent_node and always copy datatype when assigned to code nodes. This is a delicate patch that fixes subtle memory corruption bugs in libvala users and the compiler itself. It might break some application, so this commit is open for testing. --- diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala index 3b52748ff..c0f38300f 100644 --- a/vala/valaarraycreationexpression.vala +++ b/vala/valaarraycreationexpression.vala @@ -34,7 +34,7 @@ public class Vala.ArrayCreationExpression : Expression { public DataType element_type { get { return _element_type; } set { - _element_type = value; + _element_type = value.copy (); _element_type.parent_node = this; } } diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala index b37672335..11bf1a720 100644 --- a/vala/valaarraytype.vala +++ b/vala/valaarraytype.vala @@ -32,7 +32,7 @@ public class Vala.ArrayType : ReferenceType { public DataType element_type { get { return _element_type; } set { - _element_type = value; + _element_type = value.copy (); _element_type.parent_node = this; } } diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala index c7a72b6f2..c09e8abdc 100644 --- a/vala/valacastexpression.vala +++ b/vala/valacastexpression.vala @@ -44,7 +44,7 @@ public class Vala.CastExpression : Expression { public DataType type_reference { get { return _data_type; } set { - _data_type = value; + _data_type = value.copy (); _data_type.parent_node = this; } } diff --git a/vala/valacatchclause.vala b/vala/valacatchclause.vala index b2f20a491..ef1f99840 100644 --- a/vala/valacatchclause.vala +++ b/vala/valacatchclause.vala @@ -31,8 +31,9 @@ public class Vala.CatchClause : CodeNode { public DataType? error_type { get { return _data_type; } set { - _data_type = value; - if (_data_type != null) { + _data_type = null; + if (value != null) { + _data_type = value.copy (); _data_type.parent_node = this; } } diff --git a/vala/valaclass.vala b/vala/valaclass.vala index ba23a508f..a88fb01ee 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -225,10 +225,11 @@ public class Vala.Class : ObjectTypeSymbol { * @param type a class or interface reference */ public void add_base_type (DataType type) { - base_types.add (type); - type.parent_node = this; + var copy = type.copy (); + base_types.add (copy); + copy.parent_node = this; } - + /** * Returns a copy of the base type list. * @@ -556,6 +557,7 @@ public class Vala.Class : ObjectTypeSymbol { for (int i = 0; i < base_types.size; i++) { if (base_types[i] == old_type) { base_types[i] = new_type; + new_type.parent_node = this; return; } } diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala index 53b84c60e..0c789bd20 100644 --- a/vala/valaconstant.vala +++ b/vala/valaconstant.vala @@ -32,7 +32,7 @@ public class Vala.Constant : Symbol, Lockable { public DataType type_reference { get { return _data_type; } set { - _data_type = value; + _data_type = value.copy (); _data_type.parent_node = this; } } diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index 085d321e0..376e1f172 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -71,8 +71,9 @@ public abstract class Vala.DataType : CodeNode { if (type_argument_list == null) { type_argument_list = new ArrayList (); } - type_argument_list.add (arg); - arg.parent_node = this; + var copy = arg.copy (); + type_argument_list.add (copy); + copy.parent_node = this; } /** @@ -251,6 +252,7 @@ public abstract class Vala.DataType : CodeNode { for (int i = 0; i < type_argument_list.size; i++) { if (type_argument_list[i] == old_type) { type_argument_list[i] = new_type; + new_type.parent_node = this; return; } } diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala index d949c611f..14f7ffade 100644 --- a/vala/valadelegate.vala +++ b/vala/valadelegate.vala @@ -32,7 +32,7 @@ public class Vala.Delegate : TypeSymbol { public DataType return_type { get { return _return_type; } set { - _return_type = value; + _return_type = value.copy (); _return_type.parent_node = this; } } diff --git a/vala/valaexpression.vala b/vala/valaexpression.vala index 620086e98..96e037d02 100644 --- a/vala/valaexpression.vala +++ b/vala/valaexpression.vala @@ -31,18 +31,71 @@ public abstract class Vala.Expression : CodeNode { * * The semantic analyzer computes this value. */ - public DataType value_type { get; set; } + public DataType value_type { + get { + return _value_type; + } + + set { + _value_type = null; + if (value != null) { + _value_type = value.copy (); + _value_type.parent_node = this; + } + } + } + + private DataType _value_type; + + public DataType? formal_value_type { + get { + return _formal_value_type; + } + set { + _formal_value_type = null; + if (value != null) { + _formal_value_type = value.copy (); + _formal_value_type.parent_node = this; + } + } + } - public DataType? formal_value_type { get; set; } + private DataType _formal_value_type; /* * The static type this expression is expected to have. * * The semantic analyzer computes this value, lambda expressions use it. */ - public DataType target_type { get; set; } + public DataType target_type { + get { + return _target_type; + } + set { + _target_type = null; + if (value != null) { + _target_type = value.copy (); + _target_type.parent_node = this; + } + } + } + + private DataType _target_type; + + public DataType? formal_target_type { + get { + return _formal_target_type; + } + set { + _formal_target_type = null; + if (value != null) { + _formal_target_type = value.copy (); + _formal_target_type.parent_node = this; + } + } + } - public DataType? formal_target_type { get; set; } + private DataType _formal_target_type; /** * The symbol this expression refers to. diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala index 8c6522229..e10192d89 100644 --- a/vala/valaforeachstatement.vala +++ b/vala/valaforeachstatement.vala @@ -32,8 +32,9 @@ public class Vala.ForeachStatement : Block { public DataType? type_reference { get { return _data_type; } set { - _data_type = value; - if (_data_type != null) { + _data_type = null; + if (value != null) { + _data_type = value.copy (); _data_type.parent_node = this; } } diff --git a/vala/valainterface.vala b/vala/valainterface.vala index 49bc0ae2c..cc7ce13aa 100644 --- a/vala/valainterface.vala +++ b/vala/valainterface.vala @@ -95,8 +95,9 @@ public class Vala.Interface : ObjectTypeSymbol { * @param type an interface or class reference */ public void add_prerequisite (DataType type) { - prerequisites.add (type); - type.parent_node = this; + var copy = type.copy (); + prerequisites.add (copy); + copy.parent_node = this; } /** @@ -106,7 +107,9 @@ public class Vala.Interface : ObjectTypeSymbol { * @param type an interface or class reference */ public void prepend_prerequisite (DataType type) { - prerequisites.insert (0, type); + var copy = type.copy (); + prerequisites.insert (0, copy); + copy.parent_node = this; } /** @@ -349,6 +352,7 @@ public class Vala.Interface : ObjectTypeSymbol { for (int i = 0; i < prerequisites.size; i++) { if (prerequisites[i] == old_type) { prerequisites[i] = new_type; + new_type.parent_node = this; return; } } diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala index af9f51f38..156f9aa91 100644 --- a/vala/valamemberaccess.vala +++ b/vala/valamemberaccess.vala @@ -102,8 +102,9 @@ public class Vala.MemberAccess : Expression { * @param arg a type reference */ public void add_type_argument (DataType arg) { - type_argument_list.add (arg); - arg.parent_node = this; + var copy = arg.copy (); + type_argument_list.add (copy); + copy.parent_node = this; } /** @@ -160,6 +161,7 @@ public class Vala.MemberAccess : Expression { for (int i = 0; i < type_argument_list.size; i++) { if (type_argument_list[i] == old_type) { type_argument_list[i] = new_type; + new_type.parent_node = this; return; } } diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 663ae6fdf..eef04ab72 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -36,7 +36,7 @@ public class Vala.Method : Subroutine { public DataType return_type { get { return _return_type; } set { - _return_type = value; + _return_type = value.copy (); _return_type.parent_node = this; } } diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index a4121f3aa..56fb3ae34 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -32,7 +32,7 @@ public class Vala.ObjectCreationExpression : Expression { public DataType type_reference { get { return _data_type; } set { - _data_type = value; + _data_type = value.copy (); _data_type.parent_node = this; } } diff --git a/vala/valapointertype.vala b/vala/valapointertype.vala index 4bfaf34ee..5ec9228c5 100644 --- a/vala/valapointertype.vala +++ b/vala/valapointertype.vala @@ -32,7 +32,7 @@ public class Vala.PointerType : DataType { public DataType base_type { get { return _base_type; } set { - _base_type = value; + _base_type = value.copy (); _base_type.parent_node = this; } } diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala index 8a8ced49b..300fb4dd1 100644 --- a/vala/valaproperty.vala +++ b/vala/valaproperty.vala @@ -33,8 +33,9 @@ public class Vala.Property : Symbol, Lockable { public DataType? property_type { get { return _data_type; } set { - _data_type = value; + _data_type = null; if (value != null) { + _data_type = value.copy (); _data_type.parent_node = this; } } diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala index 466fe6c18..3903ae835 100644 --- a/vala/valapropertyaccessor.vala +++ b/vala/valapropertyaccessor.vala @@ -39,8 +39,9 @@ public class Vala.PropertyAccessor : Subroutine { public DataType? value_type { get { return _value_type; } set { - _value_type = value; + _value_type = null; if (value != null) { + _value_type = value.copy (); _value_type.parent_node = this; } } diff --git a/vala/valasignal.vala b/vala/valasignal.vala index 3ddc453b3..866760fe2 100644 --- a/vala/valasignal.vala +++ b/vala/valasignal.vala @@ -32,7 +32,7 @@ public class Vala.Signal : Symbol, Lockable { public DataType return_type { get { return _return_type; } set { - _return_type = value; + _return_type = value.copy (); _return_type.parent_node = this; } } diff --git a/vala/valasizeofexpression.vala b/vala/valasizeofexpression.vala index 42c1ee599..1fd80c456 100644 --- a/vala/valasizeofexpression.vala +++ b/vala/valasizeofexpression.vala @@ -32,7 +32,7 @@ public class Vala.SizeofExpression : Expression { public DataType type_reference { get { return _data_type; } set { - _data_type = value; + _data_type = value.copy (); _data_type.parent_node = this; } } diff --git a/vala/valatypeofexpression.vala b/vala/valatypeofexpression.vala index 9b0e02e13..1e932f16f 100644 --- a/vala/valatypeofexpression.vala +++ b/vala/valatypeofexpression.vala @@ -32,7 +32,7 @@ public class Vala.TypeofExpression : Expression { public DataType type_reference { get { return _data_type; } set { - _data_type = value; + _data_type = value.copy (); _data_type.parent_node = this; } } diff --git a/vala/valavariable.vala b/vala/valavariable.vala index e625e660b..a65fcbeb2 100644 --- a/vala/valavariable.vala +++ b/vala/valavariable.vala @@ -42,8 +42,9 @@ public class Vala.Variable : Symbol { public DataType? variable_type { get { return _variable_type; } set { - _variable_type = value; - if (_variable_type != null) { + _variable_type = null; + if (value != null) { + _variable_type = value.copy (); _variable_type.parent_node = this; } }