]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add g_array_index binding and fix g_array_free calls, fixes bug 519978
authorJürg Billeter <j@bitron.ch>
Mon, 24 Nov 2008 15:10:25 +0000 (15:10 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Mon, 24 Nov 2008 15:10:25 +0000 (15:10 +0000)
2008-11-24  Jürg Billeter  <j@bitron.ch>

* ccode/valaccodefunctioncall.vala:
* gobject/valaccodearraymodule.vala:
* gobject/valaccodebasemodule.vala:
* gobject/valaccodemethodcallmodule.vala:
* vala/valasemanticanalyzer.vala:
* vapi/glib-2.0.vapi:

Add g_array_index binding and fix g_array_free calls,
fixes bug 519978

svn path=/trunk/; revision=2061

ChangeLog
ccode/valaccodefunctioncall.vala
gobject/valaccodearraymodule.vala
gobject/valaccodebasemodule.vala
gobject/valaccodemethodcallmodule.vala
vala/valasemanticanalyzer.vala
vapi/glib-2.0.vapi

index 472a5f89ebd116b875d172dfa0473ceb618ebc9c..17b509c153a769645736d575c14dabe3f286bdd7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-11-24  Jürg Billeter  <j@bitron.ch>
+
+       * ccode/valaccodefunctioncall.vala:
+       * gobject/valaccodearraymodule.vala:
+       * gobject/valaccodebasemodule.vala:
+       * gobject/valaccodemethodcallmodule.vala:
+       * vala/valasemanticanalyzer.vala:
+       * vapi/glib-2.0.vapi:
+
+       Add g_array_index binding and fix g_array_free calls,
+       fixes bug 519978
+
 2008-11-22  Jürg Billeter  <j@bitron.ch>
 
        * tests/:
index e5141f04427f93e4cdd07638275bce91e1e5b652..ffecda2cff4c0717aef58968aa8f3358ac2e256d 100644 (file)
@@ -47,6 +47,10 @@ public class Vala.CCodeFunctionCall : CCodeExpression {
                arguments.add (expr);
        }
 
+       public void insert_argument (int index, CCodeExpression expr) {
+               arguments.insert (index, expr);
+       }
+
        /**
         * Returns a copy of the list of arguments.
         *
index 8ca987f8a71b87f62ee45c2823406605d8a258ca..ef302dd4cfc38e00ac09696d3a601705c586c0f3 100644 (file)
@@ -476,4 +476,25 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
                return dup_func;
        }
+
+       public override void visit_method_call (MethodCall expr) {
+               base.visit_method_call (expr);
+
+               var ccall = expr.ccodenode as CCodeFunctionCall;
+               if (ccall == null) {
+                       return;
+               }
+
+               var cid = ccall.call as CCodeIdentifier;
+               if (cid == null || cid.name != "g_array_index") {
+                       return;
+               }
+
+               // insert type argument in calls to g_array_index macro
+
+               var ma = (MemberAccess) expr.call;
+               var element_type = ma.inner.value_type.get_type_arguments ().get (0);
+
+               ccall.insert_argument (1, new CCodeIdentifier (element_type.get_cname ()));
+       }
 }
index 047bd35435ea1ae76c3db2bc2e04938a1e8e0cc2..b45dd4b4bd407844e570063c7bd7fdbed4eddcee 100644 (file)
@@ -1659,7 +1659,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
                /* set freed references to NULL to prevent further use */
                var ccomma = new CCodeCommaExpression ();
 
-               if (type.data_type == gstringbuilder_type) {
+               if (type.data_type == gstringbuilder_type || type.data_type == garray_type) {
                        ccall.add_argument (new CCodeConstant ("TRUE"));
                } else if (type is ArrayType) {
                        var array_type = (ArrayType) type;
index ccb3dd68b8484ce36393af511da36b5a7bc71cbb..561947718ce605cd9d1f8854e6c0a1fa8b86e829 100644 (file)
@@ -426,12 +426,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                if (m != null && m.binding == MemberBinding.INSTANCE && m.returns_modified_pointer) {
                        expr.ccodenode = new CCodeAssignment (instance, ccall_expr);
                } else {
-                       /* cast pointer to actual type if this is a generic method return value */
-                       if (m != null && m.return_type.type_parameter != null && expr.value_type.data_type != null) {
-                               expr.ccodenode = convert_from_generic_pointer (ccall_expr, expr.value_type);
-                       } else {
-                               expr.ccodenode = ccall_expr;
-                       }
+                       expr.ccodenode = ccall_expr;
                }
                
                if (m is ArrayResizeMethod) {
index ec91d6f0a7d79ae76ddf92cf95c20940668f649f..94b6256be5b2e788517e555ff0858c0ae71399dd 100644 (file)
@@ -56,6 +56,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public TypeSymbol initially_unowned_type;
        public DataType glist_type;
        public DataType gslist_type;
+       public DataType garray_type;
        public Class gerror_type;
        public DataType iterable_type;
        public Interface iterator_type;
@@ -108,6 +109,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 
                        glist_type = new ObjectType ((Class) glib_ns.scope.lookup ("List"));
                        gslist_type = new ObjectType ((Class) glib_ns.scope.lookup ("SList"));
+                       garray_type = new ObjectType ((Class) glib_ns.scope.lookup ("Array"));
 
                        gerror_type = (Class) glib_ns.scope.lookup ("Error");
                }
@@ -571,7 +573,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        return generic_type;
                }
                actual_type = actual_type.copy ();
-               actual_type.is_type_argument = true;
+               if (!(derived_instance_type.data_type != null && derived_instance_type.data_type.get_full_name () == "GLib.Array")) {
+                       // GArray doesn't use pointer-based generics
+                       actual_type.is_type_argument = true;
+               }
                actual_type.value_owned = actual_type.value_owned && generic_type.value_owned;
                return actual_type;
        }
index 46456eb226abca2e902096c30c21f771e4a02e31..ddc1251e7507c8e60844f8214c23c12e0edabc58 100644 (file)
@@ -3009,32 +3009,25 @@ namespace GLib {
 
        [Compact]
        public class Array<G> {
+               [CCode (cname = "len")]
+               public uint length;
+
                public Array (bool zero_terminated, bool clear, uint element_size);
                [CCode (cname = "g_array_sized_new")]
                public Array.sized (bool zero_terminated, bool clear, uint element_size, uint reserved_size);
-               [ReturnsModifiedPointer ()]
                public void append_val (G value);
-               [ReturnsModifiedPointer ()]
                public void append_vals (constpointer data, uint len);
-               [ReturnsModifiedPointer ()]
                public void prepend_val (G value);
-               [ReturnsModifiedPointer ()]
                public void prepend_vals (constpointer data, uint len);
-               [ReturnsModifiedPointer ()]
                public void insert_val (uint index, G value);
-               [ReturnsModifiedPointer ()]
                public void insert_vals (uint index, constpointer data, uint len);
-               [ReturnsModifiedPointer ()]
                public void remove_index (uint index);
-               [ReturnsModifiedPointer ()]
                public void remove_index_fast (uint index);
-               [ReturnsModifiedPointer ()]
                public void remove_range (uint index, uint length);
                public void sort (CompareFunc compare_func);
                public void sort_with_data (CompareDataFunc compare_func, void* user_data);
-               [ReturnsModifiedPointer ()]
+               public G index (uint index);
                public void set_size (uint length);
-               public string free (bool free_segment);
        }
        
        /* GTree */