From 4209a8bf53b48cf4f77d2e24fddd6bb5c5baf135 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Thu, 4 Feb 2021 19:22:07 +0100 Subject: codegen: Use g_memdup2 if target glib >= 2.68 is set See https://gitlab.gnome.org/GNOME/glib/issues/2319 --- codegen/valagvariantmodule.vala | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'codegen/valagvariantmodule.vala') diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala index 03a7193aa..4d3c692a8 100644 --- a/codegen/valagvariantmodule.vala +++ b/codegen/valagvariantmodule.vala @@ -418,7 +418,12 @@ public class Vala.GVariantModule : GValueModule { ccode.add_declaration ("gsize", new CCodeVariableDeclarator (temp_name + "_length", get_size_call)); var length = new CCodeIdentifier (temp_name + "_length"); - var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup")); + CCodeFunctionCall dup_call; + if (context.require_glib_version (2, 68)) { + dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup2")); + } else { + dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup")); + } dup_call.add_argument (get_data_call); dup_call.add_argument (length); @@ -559,7 +564,12 @@ public class Vala.GVariantModule : GValueModule { if (result != null && type.nullable) { var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof")); csizeof.add_argument (new CCodeIdentifier (get_ccode_name (st))); - var cdup = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup")); + CCodeFunctionCall cdup; + if (context.require_glib_version (2, 68)) { + cdup = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup2")); + } else { + cdup = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup")); + } cdup.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, result)); cdup.add_argument (csizeof); result = cdup; @@ -731,7 +741,12 @@ public class Vala.GVariantModule : GValueModule { var gvariant_type = new CCodeFunctionCall (new CCodeIdentifier ("G_VARIANT_TYPE")); gvariant_type.add_argument (new CCodeConstant ("\"%s\"".printf (array_type.get_type_signature ()))); - var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup")); + CCodeFunctionCall dup_call; + if (context.require_glib_version (2, 68)) { + dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup2")); + } else { + dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup")); + } dup_call.add_argument (array_expr); dup_call.add_argument (get_array_length (array_expr, 1)); ccode.add_declaration (get_ccode_name (array_type), new CCodeVariableDeclarator (buffer_name, dup_call)); -- cgit v1.2.1