summaryrefslogtreecommitdiff
path: root/codegen/valaccodearraymodule.vala
diff options
context:
space:
mode:
Diffstat (limited to 'codegen/valaccodearraymodule.vala')
-rw-r--r--codegen/valaccodearraymodule.vala16
1 files changed, 14 insertions, 2 deletions
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 39a98e45f..cd9377512 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -57,8 +57,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
return;
}
- var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
- gnew.add_argument (new CCodeIdentifier (get_ccode_name (expr.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 (expr.element_type)));
+ }
bool first = true;
CCodeExpression cexpr = null;
@@ -83,6 +89,12 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
gnew.add_argument (cexpr);
+ if (context.profile == Profile.POSIX) {
+ var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
+ csizeof.add_argument (new CCodeIdentifier (get_ccode_name (expr.element_type)));
+ gnew.add_argument (csizeof);
+ }
+
var temp_var = get_temp_variable (expr.value_type, true, expr);
var name_cnode = get_variable_cexpression (temp_var.name);
int i = 0;