[vala/staging] codegen: Use alternative for g_new0 in POSIX profile
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Use alternative for g_new0 in POSIX profile
- Date: Sat, 19 Oct 2019 08:39:09 +0000 (UTC)
commit b45af91bf7a974973b5c0abc164326b54512642b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Oct 19 00:12:26 2019 +0200
codegen: Use alternative for g_new0 in POSIX profile
codegen/valaccodearraymodule.vala | 16 ++++++++++++++--
codegen/valaccodebasemodule.vala | 16 +++++++++++++---
2 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index e71f41d70..2d122035f 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -519,8 +519,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
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
@@ -529,6 +535,12 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
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);
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index d3f4f416d..cc737edd8 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3040,9 +3040,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
} 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]