[perl-glib-object-introspection] Hush a few compiler warnings



commit d641f26e8e1c26925e195494ea84e6f8abfc0241
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Sat Sep 28 20:03:23 2019 +0200

    Hush a few compiler warnings

 GObjectIntrospection.xs        |  8 +++---
 Makefile.PL                    | 11 +++++---
 gperl-i11n-invoke.c            | 21 +++++++++++-----
 gperl-i11n-marshal-array.c     | 57 +++++++++++++++++++++++++++++-------------
 gperl-i11n-marshal-callback.c  |  2 +-
 gperl-i11n-marshal-interface.c |  2 +-
 gperl-i11n-marshal-list.c      |  6 ++---
 7 files changed, 72 insertions(+), 35 deletions(-)
---
diff --git a/GObjectIntrospection.xs b/GObjectIntrospection.xs
index aca33f8..3b09e2b 100644
--- a/GObjectIntrospection.xs
+++ b/GObjectIntrospection.xs
@@ -17,14 +17,16 @@
  *
  */
 
-#include "build/gi-version.h"
-
 #include <gperl.h>
 #include <gperl_marshal.h>
 
 #include <girepository.h>
 #include <girffi.h>
 
+#ifndef GI_CHECK_VERSION
+# include "build/gi-version.h"
+#endif
+
 /* #define NOISY */
 #ifdef NOISY
 # define dwarn(msg...) G_STMT_START { \
@@ -181,7 +183,7 @@ static void prepare_invocation_info (GPerlI11nInvocationInfo *iinfo,
 static void clear_invocation_info (GPerlI11nInvocationInfo *iinfo);
 
 static void free_after_call (GPerlI11nInvocationInfo *iinfo,
-                             GFunc func, gpointer data);
+                             GDestroyNotify func, gpointer data);
 static void invoke_free_after_call_handlers (GPerlI11nInvocationInfo *iinfo);
 
 #if GI_CHECK_VERSION (1, 33, 10)
diff --git a/Makefile.PL b/Makefile.PL
index e34929c..43a1b3e 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -141,10 +141,13 @@ mkdir 'build', 0777;
 
 compile_test_libraries();
 
-ExtUtils::PkgConfig->write_version_macros (
-  "build/gi-version.h",
-  "gobject-introspection-1.0" => "GI",
-);
+my $have_gi_1_60 = ExtUtils::PkgConfig->atleast_version('gobject-introspection-1.0', '1.60.0');
+if (!$have_gi_1_60) {
+  ExtUtils::PkgConfig->write_version_macros (
+    "build/gi-version.h",
+    "gobject-introspection-1.0" => "GI",
+  );
+}
 
 my $deps = ExtUtils::Depends->new ('Glib::Object::Introspection' => 'Glib');
 $deps->set_inc ($cfg{cflags});
diff --git a/gperl-i11n-invoke.c b/gperl-i11n-invoke.c
index f0bd490..00fbbeb 100644
--- a/gperl-i11n-invoke.c
+++ b/gperl-i11n-invoke.c
@@ -50,6 +50,13 @@ prepare_invocation_info (GPerlI11nInvocationInfo *iinfo,
        iinfo->free_after_call = NULL;
 }
 
+static void
+_free_array_info (gpointer ai, gpointer user_data)
+{
+       PERL_UNUSED_VAR (user_data);
+       g_free (ai);
+}
+
 static void
 clear_invocation_info (GPerlI11nInvocationInfo *iinfo)
 {
@@ -61,7 +68,7 @@ clear_invocation_info (GPerlI11nInvocationInfo *iinfo)
        g_slist_free (iinfo->callback_infos);
        iinfo->callback_infos = NULL;
 
-       g_slist_foreach (iinfo->array_infos, (GFunc) g_free, NULL);
+       g_slist_foreach (iinfo->array_infos, _free_array_info, NULL);
        g_slist_free (iinfo->array_infos);
        iinfo->array_infos = NULL;
 }
@@ -69,12 +76,12 @@ clear_invocation_info (GPerlI11nInvocationInfo *iinfo)
 /* ------------------------------------------------------------------------- */
 
 typedef struct {
-       GFunc func;
+       GDestroyNotify func;
        gpointer data;
 } FreeClosure;
 
 static void
-free_after_call (GPerlI11nInvocationInfo *iinfo, GFunc func, gpointer data)
+free_after_call (GPerlI11nInvocationInfo *iinfo, GDestroyNotify func, gpointer data)
 {
        FreeClosure *closure = g_new (FreeClosure, 1);
        closure->func = func;
@@ -84,9 +91,11 @@ free_after_call (GPerlI11nInvocationInfo *iinfo, GFunc func, gpointer data)
 }
 
 static void
-_invoke_free_closure (FreeClosure *closure)
+_invoke_free_closure (gpointer closure_in, gpointer user_data)
 {
-       closure->func (closure->data, NULL);
+       FreeClosure *closure = closure_in;
+       PERL_UNUSED_VAR (user_data);
+       closure->func (closure->data);
        g_free (closure);
 }
 
@@ -96,5 +105,5 @@ invoke_free_after_call_handlers (GPerlI11nInvocationInfo *iinfo)
        /* We free the FreeClosures themselves directly after invoking them.  The list
           is freed in clear_invocation_info. */
        g_slist_foreach (iinfo->free_after_call,
-                        (GFunc) _invoke_free_closure, NULL);
+                        _invoke_free_closure, NULL);
 }
diff --git a/gperl-i11n-marshal-array.c b/gperl-i11n-marshal-array.c
index 3e2274d..12914d8 100644
--- a/gperl-i11n-marshal-array.c
+++ b/gperl-i11n-marshal-array.c
@@ -42,24 +42,42 @@ _free_raw_array (gpointer raw_array)
 }
 
 static void
-_free_array (GArray *array)
+_free_array (GArray *array, gboolean free_content)
 {
-       dwarn ("%p\n", array);
-       g_array_free (array, TRUE);
+       dwarn ("%p: free_content=%d\n", array, free_content);
+       g_array_free (array, free_content);
 }
 
 static void
-_free_ptr_array (GPtrArray *array)
+_free_array_and_content (gpointer array)
 {
-       dwarn ("%p\n", array);
-       g_ptr_array_free (array, TRUE);
+       _free_array (array, TRUE);
 }
 
 static void
-_free_byte_array (GByteArray *array)
+_free_ptr_array (GPtrArray *array, gboolean free_content)
 {
-       dwarn ("%p\n", array);
-       g_byte_array_free (array, TRUE);
+       dwarn ("%p: free_content=%d\n", array, free_content);
+       g_ptr_array_free (array, free_content);
+}
+
+static void
+_free_ptr_array_and_content (gpointer array)
+{
+       _free_ptr_array (array, TRUE);
+}
+
+static void
+_free_byte_array (GByteArray *array, gboolean free_content)
+{
+       dwarn ("%p: free_content=%d\n", array, free_content);
+       g_byte_array_free (array, free_content);
+}
+
+static void
+_free_byte_array_and_content (gpointer array)
+{
+       _free_byte_array (array, TRUE);
 }
 
 /* This may call Perl code (via arg_to_sv), so it needs to be wrapped with
@@ -179,18 +197,23 @@ array_to_sv (GITypeInfo *info,
        }
 
        if (transfer >= GI_TRANSFER_CONTAINER) {
+               /* When we were transfered ownership of the array, we need to
+                  free it and its element storage here.  This is safe since,
+                  if the array was flat, we made sure to take copies of the
+                  elements above. */
+               free_element_data = TRUE;
                switch (array_type) {
                case GI_ARRAY_TYPE_C:
                        _free_raw_array (array);
                        break;
                case GI_ARRAY_TYPE_ARRAY:
-                       _free_array (array);
+                       _free_array (array, free_element_data);
                        break;
                case GI_ARRAY_TYPE_PTR_ARRAY:
-                       _free_ptr_array (array);
+                       _free_ptr_array (array, free_element_data);
                        break;
                case GI_ARRAY_TYPE_BYTE_ARRAY:
-                       _free_byte_array (array);
+                       _free_byte_array (array, free_element_data);
                        break;
                }
        }
@@ -219,7 +242,7 @@ sv_to_array (GITransfer transfer,
        GPerlI11nArrayInfo *array_info = NULL;
        gpointer array = NULL;
        gpointer return_array;
-       GFunc return_array_free_func;
+       GDestroyNotify return_array_free_func;
        gboolean is_zero_terminated = FALSE;
        gsize item_size;
        gboolean need_struct_value_semantics;
@@ -324,16 +347,16 @@ sv_to_array (GITransfer transfer,
        switch (array_type) {
        case GI_ARRAY_TYPE_C:
                return_array = g_array_free (array, FALSE);
-               return_array_free_func = (GFunc) _free_raw_array;
+               return_array_free_func = _free_raw_array;
                break;
        case GI_ARRAY_TYPE_ARRAY:
-               return_array_free_func = (GFunc) _free_array;
+               return_array_free_func = _free_array_and_content;
                break;
        case GI_ARRAY_TYPE_PTR_ARRAY:
-               return_array_free_func = (GFunc) _free_ptr_array;
+               return_array_free_func = _free_ptr_array_and_content;
                break;
        case GI_ARRAY_TYPE_BYTE_ARRAY:
-               return_array_free_func = (GFunc) _free_byte_array;
+               return_array_free_func = _free_byte_array_and_content;
                break;
        }
 
diff --git a/gperl-i11n-marshal-callback.c b/gperl-i11n-marshal-callback.c
index 51e09ec..e937af7 100644
--- a/gperl-i11n-marshal-callback.c
+++ b/gperl-i11n-marshal-callback.c
@@ -33,7 +33,7 @@ sv_to_callback (GIArgInfo * arg_info,
            case GI_SCOPE_TYPE_CALL:
                dwarn ("  scope = 'call'\n");
                free_after_call (invocation_info,
-                                (GFunc) release_perl_callback, callback_info);
+                                release_perl_callback, callback_info);
                break;
            case GI_SCOPE_TYPE_NOTIFIED:
                dwarn ("  scope = 'notified'\n");
diff --git a/gperl-i11n-marshal-interface.c b/gperl-i11n-marshal-interface.c
index 9715209..7e0b4fc 100644
--- a/gperl-i11n-marshal-interface.c
+++ b/gperl-i11n-marshal-interface.c
@@ -475,7 +475,7 @@ _sv_to_class_struct_pointer (SV *sv, GPerlI11nInvocationInfo *iinfo)
                        /* If peek() produced NULL, the class has not been
                         * instantiated yet and needs to be created. */
                        pointer = g_type_class_ref (class_type);
-                       free_after_call (iinfo, (GFunc) g_type_class_unref, pointer);
+                       free_after_call (iinfo, g_type_class_unref, pointer);
                }
                dwarn ("     type class = %p\n", pointer);
        }
diff --git a/gperl-i11n-marshal-list.c b/gperl-i11n-marshal-list.c
index a392e71..21e0e45 100644
--- a/gperl-i11n-marshal-list.c
+++ b/gperl-i11n-marshal-list.c
@@ -1,14 +1,14 @@
 /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8; -*- */
 
 static void
-free_list (GList *list)
+_free_list (gpointer list)
 {
        dwarn ("%p\n", list);
        g_list_free (list);
 }
 
 static void
-free_slist (GSList *list)
+_free_slist (gpointer list)
 {
        dwarn ("%p\n", list);
        g_slist_free (list);
@@ -129,7 +129,7 @@ sv_to_glist (GITransfer transfer, GITypeInfo * type_info, SV * sv, GPerlI11nInvo
 
        if (GI_TRANSFER_NOTHING == transfer)
                free_after_call (iinfo,
-                                is_slist ? ((GFunc)free_slist) : ((GFunc)free_list),
+                                is_slist ? _free_slist : _free_list,
                                 list);
 
        dwarn ("  -> list = %p, length = %d\n", list, g_list_length (list));


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