[gobject-introspection/ebassi/pre-release: 1/2] Use g_memdup2() with newer versions of GLib




commit 0de0b308b0567f6cd1c284f3c11678d6794df7b6
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Mar 12 18:54:47 2021 +0000

    Use g_memdup2() with newer versions of GLib
    
    The g_memdup() function has been deprecated, so we should use the new
    g_memdup2() function if available.

 girepository/giconstantinfo.c | 10 +++++++++-
 tests/scanner/foo.c           | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/girepository/giconstantinfo.c b/girepository/giconstantinfo.c
index c18a9d3f..a9d4cbc0 100644
--- a/girepository/giconstantinfo.c
+++ b/girepository/giconstantinfo.c
@@ -128,7 +128,15 @@ g_constant_info_get_value (GIConstantInfo *info,
   if (blob->type.flags.reserved == 0 && blob->type.flags.reserved2 == 0)
     {
       if (blob->type.flags.pointer)
-       value->v_pointer = g_memdup (&rinfo->typelib->data[blob->offset], blob->size);
+        {
+#if GLIB_CHECK_VERSION (2, 67, 5)
+          gsize blob_size = blob->size;
+
+         value->v_pointer = g_memdup2 (&rinfo->typelib->data[blob->offset], blob_size);
+#else
+         value->v_pointer = g_memdup (&rinfo->typelib->data[blob->offset], blob->size);
+#endif
+        }
       else
        {
          switch (blob->type.flags.tag)
diff --git a/tests/scanner/foo.c b/tests/scanner/foo.c
index e409e0a3..cd45362d 100644
--- a/tests/scanner/foo.c
+++ b/tests/scanner/foo.c
@@ -410,7 +410,11 @@ struct _RegressFooBoxed
 RegressFooBoxed *
 regress_foo_boxed_copy (const RegressFooBoxed *boxed)
 {
+#if GLIB_CHECK_VERSION (2, 67, 5)
+  return (RegressFooBoxed *)g_memdup2 (boxed, sizeof (RegressFooBoxed));
+#else
   return (RegressFooBoxed *)g_memdup (boxed, sizeof (RegressFooBoxed));
+#endif
 }
 
 void
@@ -453,7 +457,11 @@ struct _RegressFooDBusData
 RegressFooDBusData *
 regress_foo_dbus_data_copy (const RegressFooDBusData *boxed)
 {
+#if GLIB_CHECK_VERSION (2, 67, 5)
+  return (RegressFooDBusData *)g_memdup2 (boxed, sizeof (RegressFooDBusData));
+#else
   return (RegressFooDBusData *)g_memdup (boxed, sizeof (RegressFooDBusData));
+#endif
 }
 
 void
@@ -478,7 +486,11 @@ regress_foo_dbus_data_get_type (void)
 static RegressFooBRect *
 regress_foo_brect_copy (const RegressFooBRect *boxed)
 {
+#if GLIB_CHECK_VERSION (2, 67, 5)
+  return (RegressFooBRect *)g_memdup2 (boxed, sizeof (RegressFooBRect));
+#else
   return (RegressFooBRect *)g_memdup (boxed, sizeof (RegressFooBRect));
+#endif
 }
 
 GType
@@ -496,7 +508,11 @@ regress_foo_brect_get_type (void)
 static RegressFooBUnion *
 regress_foo_bunion_copy (const RegressFooBUnion *boxed)
 {
+#if GLIB_CHECK_VERSION (2, 67, 5)
+  return (RegressFooBUnion *)g_memdup2 (boxed, sizeof (RegressFooBUnion));
+#else
   return (RegressFooBUnion *)g_memdup (boxed, sizeof (RegressFooBUnion));
+#endif
 }
 
 GType
@@ -582,7 +598,11 @@ struct _RegressFooHidden
 RegressFooHidden *
 regress_foo_hidden_copy (const RegressFooHidden *boxed)
 {
+#if GLIB_CHECK_VERSION (2, 67, 5)
+  return (RegressFooHidden *)g_memdup2 (boxed, sizeof (RegressFooHidden));
+#else
   return (RegressFooHidden *)g_memdup (boxed, sizeof (RegressFooHidden));
+#endif
 }
 
 void


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