if (requires_copy (array_type.element_type)) {
var cvardecl = new CCodeVariableDeclarator ("result");
- var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
- gnew.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
+ CCodeFunctionCall gnew;
+ if (context.profile == Profile.POSIX) {
+ cfile.add_include ("stdlib.h");
+ gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
+ } else {
+ gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
+ gnew.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
+ }
CCodeExpression length_expr = new CCodeIdentifier ("length");
// add extra item to have array NULL-terminated for all reference types
}
gnew.add_argument (length_expr);
+ if (context.profile == Profile.POSIX) {
+ var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
+ csizeof.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
+ gnew.add_argument (csizeof);
+ }
+
ccode.add_declaration (get_ccode_name (array_type), cvardecl);
ccode.add_assignment (new CCodeIdentifier ("result"), gnew);
} else {
ccode.add_declaration (get_ccode_name (value_type), new CCodeVariableDeclarator ("dup"));
- var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
- creation_call.add_argument (new CCodeConstant (get_ccode_name (value_type.type_symbol)));
- creation_call.add_argument (new CCodeConstant ("1"));
+ CCodeFunctionCall creation_call;
+ if (context.profile == Profile.POSIX) {
+ cfile.add_include ("stdlib.h");
+ creation_call = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
+ creation_call.add_argument (new CCodeConstant ("1"));
+ var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
+ csizeof.add_argument (new CCodeIdentifier (get_ccode_name (value_type.type_symbol)));
+ creation_call.add_argument (csizeof);
+ } else {
+ creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
+ creation_call.add_argument (new CCodeIdentifier (get_ccode_name (value_type.type_symbol)));
+ creation_call.add_argument (new CCodeConstant ("1"));
+ }
ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call);
var st = value_type.type_symbol as Struct;