From: Rico Tzschichholz Date: Fri, 18 Oct 2019 22:12:26 +0000 (+0200) Subject: codegen: Use alternative for g_renew in POSIX profile X-Git-Tag: 0.47.1~62 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fkeep-around%2F7841739b199ac5f1901e32cd9c0e90e9d4f5afa3;p=thirdparty%2Fvala.git codegen: Use alternative for g_renew in POSIX profile --- diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala index 2d122035f..6a7ba9337 100644 --- a/codegen/valaccodearraymodule.vala +++ b/codegen/valaccodearraymodule.vala @@ -663,15 +663,29 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { var length = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("length")); var size = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("size")); - var renew_call = new CCodeFunctionCall (new CCodeIdentifier ("g_renew")); - renew_call.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type))); - renew_call.add_argument (array); + CCodeFunctionCall renew_call; + if (context.profile == Profile.POSIX) { + cfile.add_include ("stdlib.h"); + renew_call = new CCodeFunctionCall (new CCodeIdentifier ("realloc")); + renew_call.add_argument (array); + } else { + renew_call = new CCodeFunctionCall (new CCodeIdentifier ("g_renew")); + renew_call.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type))); + renew_call.add_argument (array); + } + CCodeExpression renew_call_size; if (array_type.element_type.is_reference_type_or_type_parameter ()) { // NULL terminate array - renew_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, size, new CCodeConstant ("1"))); + renew_call_size = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, size, new CCodeConstant ("1")); } else { - renew_call.add_argument (size); + renew_call_size = size; + } + if (context.profile == Profile.POSIX) { + var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof")); + csizeof.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type))); + renew_call_size = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, size, csizeof); } + renew_call.add_argument (renew_call_size); var csizecheck = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, length, size); ccode.open_if (csizecheck); diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala index e9b7192d7..bc5eb16d7 100644 --- a/vala/valaarraytype.vala +++ b/vala/valaarraytype.vala @@ -130,7 +130,11 @@ public class Vala.ArrayType : ReferenceType { resize_method.return_type = new VoidType (); resize_method.access = SymbolAccessibility.PUBLIC; - resize_method.set_attribute_string ("CCode", "cname", "g_renew"); + if (CodeContext.get ().profile == Profile.POSIX) { + resize_method.set_attribute_string ("CCode", "cname", "realloc"); + } else { + resize_method.set_attribute_string ("CCode", "cname", "g_renew"); + } resize_method.add_parameter (new Parameter ("length", length_type));