[Vala] [PATCH] Reference list members when referencing a list.



This should make assignments to values of type List<G> work.

Nevertheless we have to think about how assignments to such types can be
improved: Deep copies avoid memory-leaks, but they are deadly wrong as
no user of Vala would expect such a heavy operation on simple assignments.
This deep copy dramatically increases runtime complexity for all methods
working with list references by factor n.
---
 trunk/vala/vala/valacodegenerator.vala |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/trunk/vala/vala/valacodegenerator.vala b/trunk/vala/vala/valacodegenerator.vala
index 5f22c67..80ea065 100644
--- a/trunk/vala/vala/valacodegenerator.vala
+++ b/trunk/vala/vala/valacodegenerator.vala
@@ -3387,6 +3387,29 @@ public class Vala.CodeGenerator : CodeVisitor {
                        
                        var ccomma = new CCodeCommaExpression ();
                        ccomma.append_expression (new CCodeAssignment (ctemp, (CCodeExpression) 
expr.ccodenode));
+
+                       if (ref_function == "g_list_copy") {
+                               bool is_ref = false;
+                               bool is_class = false;
+                               bool is_interface = false;
+
+                               foreach (TypeReference type_arg in expr.static_type.get_type_arguments ()) {
+                                       is_ref |= type_arg.takes_ownership;
+                                       is_class |= type_arg.data_type is Class;
+                                       is_interface |= type_arg.data_type is Interface;
+                               }
+                       
+                               if (is_ref && (is_class || is_interface)) {
+                                       var crefcall = new CCodeFunctionCall (new CCodeIdentifier 
("g_list_foreach"));
+
+                                       crefcall.add_argument (ctemp);
+                                       crefcall.add_argument (new CCodeIdentifier ("(GFunc) g_object_ref"));
+                                       crefcall.add_argument (new CCodeConstant ("NULL"));
+
+                                       ccomma.append_expression (crefcall);
+                               }
+                       }
+
                        ccomma.append_expression (new CCodeConditionalExpression (cisnull, new CCodeConstant 
("NULL"), ccall));
 
                        return ccomma;
-- 
1.4.4.2




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