}
// create a special GDestroyNotify for created GArray and set with g_array_set_clear_func (since glib 2.32)
- if (cl == garray_type) {
+ if (cl != null && cl == garray_type) {
var type_arg = expr.type_reference.get_type_arguments ().get (0);
if (requires_destroy (type_arg)) {
var clear_func = new CCodeFunctionCall (new CCodeIdentifier ("g_array_set_clear_func"));
var creturn_type = c.return_type.copy ();
if (c is CreationMethod) {
unowned Class? cl = c.parent_symbol as Class;
+ unowned Struct? st = c.parent_symbol as Struct;
if (cl != null) {
// object creation methods return the new object in C
// in Vala they have no return type
creturn_type = new ObjectType (cl);
+ } else if (st != null && st.is_simple_type ()) {
+ // constructors return simple type structs by value
+ creturn_type = new StructValueType (st);
}
} else if (c.return_type.is_real_non_null_struct_type ()) {
// structs are returned via out parameter
}
ccode.add_expression (cinitcall);
}
+ } else if (m.parent_symbol is Struct) {
+ unowned Struct st = (Struct) m.parent_symbol;
+ if (st.is_simple_type ()) {
+ var vardecl = new CCodeVariableDeclarator ("self", default_value_for_type (creturn_type, true));
+ vardecl.init0 = true;
+ ccode.add_declaration (get_ccode_name (creturn_type), vardecl);
+ } else {
+ // memset needs string.h
+ cfile.add_include ("string.h");
+ var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
+ czero.add_argument (new CCodeIdentifier ("self"));
+ czero.add_argument (new CCodeConstant ("0"));
+ czero.add_argument (new CCodeIdentifier ("sizeof (%s)".printf (get_ccode_name (st))));
+ ccode.add_expression (czero);
+ }
} else {
- var st = (Struct) m.parent_symbol;
-
- // memset needs string.h
- cfile.add_include ("string.h");
- var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
- czero.add_argument (new CCodeIdentifier ("self"));
- czero.add_argument (new CCodeConstant ("0"));
- czero.add_argument (new CCodeIdentifier ("sizeof (%s)".printf (get_ccode_name (st))));
- ccode.add_expression (czero);
+ Report.error (m.source_reference, "internal: creation method not supported in `%s'", m.parent_symbol.get_full_name ());
}
}
}
ccode.add_return (cresult);
+ } else if (current_type_symbol is Struct && ((Struct) current_type_symbol).is_simple_type ()) {
+ // constructors return simple type structs by value
+ ccode.add_return (new CCodeIdentifier ("self"));
}
}
var base_type = new ObjectType ((Class) m.base_method.parent_symbol);
instance_param = new CCodeParameter ("base", get_ccode_name (base_type));
} else {
- if (m.parent_symbol is Struct && !((Struct) m.parent_symbol).is_simple_type ()) {
+ unowned Struct? st = m.parent_symbol as Struct;
+ if (st != null && !st.is_simple_type ()) {
instance_param = new CCodeParameter ("*self", get_ccode_name (this_type));
+ } else if (st != null && st.is_simple_type () && m is CreationMethod) {
+ // constructors return simple type structs by value
} else {
instance_param = new CCodeParameter ("self", get_ccode_name (this_type));
}
}
- cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), instance_param);
+ if (instance_param != null) {
+ cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), instance_param);
+ }
} else if (m.binding == MemberBinding.CLASS) {
var this_type = SemanticAnalyzer.get_this_type (m);
var class_param = new CCodeParameter ("klass", get_ccode_name (this_type));
decl_space.add_type_definition (instance_struct);
}
+ if (st.is_simple_type ()) {
+ return;
+ }
+
var function = new CCodeFunction (get_ccode_dup_function (st), get_ccode_name (st) + "*");
if (st.is_private_symbol ()) {
function.modifiers = CCodeModifiers.STATIC;
add_struct_destroy_function (st);
}
- add_struct_dup_function (st);
- add_struct_free_function (st);
+ if (!st.is_simple_type ()) {
+ add_struct_dup_function (st);
+ add_struct_free_function (st);
+ }
}
instance_finalize_context = old_instance_finalize_context;