+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/:
arguments.add (expr);
}
+ public void insert_argument (int index, CCodeExpression expr) {
+ arguments.insert (index, expr);
+ }
+
/**
* Returns a copy of the list of arguments.
*
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 ()));
+ }
}
/* 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;
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) {
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;
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");
}
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;
}
[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 */