[vala/staging] codegen: Use g_memdup2 if target glib >= 2.68 is set



commit 4209a8bf53b48cf4f77d2e24fddd6bb5c5baf135
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Feb 4 19:22:07 2021 +0100

    codegen: Use g_memdup2 if target glib >= 2.68 is set
    
    See https://gitlab.gnome.org/GNOME/glib/issues/2319

 codegen/valaccodearraymodule.vala |  7 ++++++-
 codegen/valagvariantmodule.vala   | 21 ++++++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index b2b2e7e1e..9a010e360 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -636,7 +636,12 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
                                ccode.add_return (new CCodeIdentifier ("result"));
                        } else {
-                               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 (new CCodeIdentifier ("self"));
                                dup_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, 
length_expr, sizeof_call));
 
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));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]