From: Jürg Billeter Date: Mon, 24 Nov 2008 15:10:25 +0000 (+0000) Subject: Add g_array_index binding and fix g_array_free calls, fixes bug 519978 X-Git-Tag: VALA_0_5_2~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e081f705d62160cc6e63c4650a7bad5cb5ccdd46;p=thirdparty%2Fvala.git Add g_array_index binding and fix g_array_free calls, fixes bug 519978 2008-11-24 Jürg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index 472a5f89e..17b509c15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-11-24 Jürg Billeter + + * 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 * tests/: diff --git a/ccode/valaccodefunctioncall.vala b/ccode/valaccodefunctioncall.vala index e5141f044..ffecda2cf 100644 --- a/ccode/valaccodefunctioncall.vala +++ b/ccode/valaccodefunctioncall.vala @@ -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. * diff --git a/gobject/valaccodearraymodule.vala b/gobject/valaccodearraymodule.vala index 8ca987f8a..ef302dd4c 100644 --- a/gobject/valaccodearraymodule.vala +++ b/gobject/valaccodearraymodule.vala @@ -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 ())); + } } diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala index 047bd3543..b45dd4b4b 100644 --- a/gobject/valaccodebasemodule.vala +++ b/gobject/valaccodebasemodule.vala @@ -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; diff --git a/gobject/valaccodemethodcallmodule.vala b/gobject/valaccodemethodcallmodule.vala index ccb3dd68b..561947718 100644 --- a/gobject/valaccodemethodcallmodule.vala +++ b/gobject/valaccodemethodcallmodule.vala @@ -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) { diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index ec91d6f0a..94b6256be 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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; } diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 46456eb22..ddc1251e7 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -3009,32 +3009,25 @@ namespace GLib { [Compact] public class Array { + [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 */