Commit 2c25e8d6 authored by Jürg Billeter's avatar Jürg Billeter

posix: Fix array creation and destruction in POSIX profile

Based on patch by pancake.
parent 57416211
......@@ -65,8 +65,15 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
return;
}
var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
gnew.add_argument (new CCodeIdentifier (expr.element_type.get_cname ()));
CCodeFunctionCall gnew;
if (context.profile == Profile.POSIX) {
source_declarations.add_include ("stdlib.h");
gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
} else {
gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
gnew.add_argument (new CCodeIdentifier (expr.element_type.get_cname ()));
}
bool first = true;
CCodeExpression cexpr = null;
......@@ -99,6 +106,12 @@ internal 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 (expr.element_type.get_cname ()));
gnew.add_argument (csizeof);
}
if (expr.initializer_list != null) {
var ce = new CCodeCommaExpression ();
var temp_var = get_temp_variable (expr.value_type, true, expr);
......
......@@ -2470,9 +2470,17 @@ internal class Vala.CCodeBaseModule : CCodeModule {
return new CCodeIdentifier (func_name);
}
} else if (type is ArrayType) {
return new CCodeIdentifier ("g_free");
if (context.profile == Profile.POSIX) {
return new CCodeIdentifier ("free");
} else {
return new CCodeIdentifier ("g_free");
}
} else if (type is PointerType) {
return new CCodeIdentifier ("g_free");
if (context.profile == Profile.POSIX) {
return new CCodeIdentifier ("free");
} else {
return new CCodeIdentifier ("g_free");
}
} else {
return new CCodeConstant ("NULL");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment