[perl-Glib] Avoid deprecated API with modern GLib



commit a066cb6521460dcad77e72d34e8478cac5493f54
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Nov 11 12:45:23 2013 +0000

    Avoid deprecated API with modern GLib
    
    We want to keep the ability to build perl-Glib with ancient versions of
    GLib, but we also want to avoid compiler warnings when compiling against
    modern versions of GLib. This means avoiding deprecated API, and trying
    to keep up with the development of the library as much as possible.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711840

 GClosure.xs |   17 +++++++++++++++++
 GObject.xs  |    3 ++-
 GSignal.xs  |   13 ++++++++++---
 GType.xs    |   13 +++++++++++++
 Glib.xs     |    6 +++++-
 5 files changed, 47 insertions(+), 5 deletions(-)
---
diff --git a/GClosure.xs b/GClosure.xs
index 5c38d01..b37870f 100644
--- a/GClosure.xs
+++ b/GClosure.xs
@@ -189,6 +189,7 @@ _closure_hand_to_main (GClosure * closure,
                        gpointer marshal_data)
 {
        MarshallerArgs args;
+
        args.closure = closure;
        args.return_value = return_value;
        args.n_param_values = n_param_values;
@@ -198,16 +199,32 @@ _closure_hand_to_main (GClosure * closure,
 
        /* We need to wait for the other thread to finish marshalling to avoid
         * gperl_closure_marshal returning prematurely. */
+#if GLIB_CHECK_VERSION (2, 32, 0)
+       /* FIXME: we should put these on the stack, but it gets real ugly real fast */
+       args.done_cond = g_slice_new (GCond);
+       g_cond_init (args.done_cond);
+       args.done_mutex = g_slice_new (GMutex);
+       g_mutex_init (args.done_mutex);
+#else
        args.done_cond = g_cond_new ();
        args.done_mutex = g_mutex_new ();
+#endif /* 2.32 */
+
        g_mutex_lock (args.done_mutex);
                /* FIXME: Should we use a higher priority? */
                g_idle_add (_closure_remarshal, &args);
                g_cond_wait (args.done_cond, args.done_mutex);
        g_mutex_unlock (args.done_mutex);
 
+#if GLIB_CHECK_VERSION (2, 32, 0)
+       g_cond_clear (args.done_cond);
+       g_slice_free (GCond, args.done_cond);
+       g_mutex_clear (args.done_mutex);
+       g_slice_free (GMutex, args.done_mutex);
+#else
        g_cond_free (args.done_cond);
        g_mutex_free (args.done_mutex);
+#endif /* 2.32 */
 }
 
 =item GClosure * gperl_closure_new (SV * callback, SV * data, gboolean swap)
diff --git a/GObject.xs b/GObject.xs
index 0a1277d..74e04ad 100644
--- a/GObject.xs
+++ b/GObject.xs
@@ -1123,7 +1123,8 @@ _inc_ref_and_count (GObject * key, gint value, gpointer user_data)
 {
        PERL_UNUSED_VAR (user_data);
        g_object_ref (key);
-       g_hash_table_replace (perl_gobjects, key, GINT_TO_POINTER (++value));
+       value += 1;
+       g_hash_table_replace (perl_gobjects, key, GINT_TO_POINTER (value));
 }
 #endif
 
diff --git a/GSignal.xs b/GSignal.xs
index df7f56d..474d104 100644
--- a/GSignal.xs
+++ b/GSignal.xs
@@ -37,12 +37,19 @@
  * modifying it.
  */
 #ifdef G_THREADS_ENABLED
-# define GPERL_REC_LOCK_DEFINE_STATIC(name)    \
+# if GLIB_CHECK_VERSION (2, 32, 0)
+#  define GPERL_REC_LOCK_DEFINE_STATIC(name)    static GPERL_REC_LOCK_DEFINE (name)
+#  define GPERL_REC_LOCK_DEFINE(name)           GRecMutex G_LOCK_NAME (name)
+#  define GPERL_REC_LOCK(name)                  g_rec_mutex_lock (&G_LOCK_NAME (name))
+#  define GPERL_REC_UNLOCK(name)                g_rec_mutex_unlock (&G_LOCK_NAME (name))
+# else
+#  define GPERL_REC_LOCK_DEFINE_STATIC(name)   \
        GStaticRecMutex G_LOCK_NAME (name) = G_STATIC_REC_MUTEX_INIT
-# define GPERL_REC_LOCK(name)  \
+#  define GPERL_REC_LOCK(name) \
        g_static_rec_mutex_lock (&G_LOCK_NAME (name))
-# define GPERL_REC_UNLOCK(name)        \
+#  define GPERL_REC_UNLOCK(name)       \
        g_static_rec_mutex_unlock (&G_LOCK_NAME (name))
+# endif
 #else
 # define GPERL_REC_LOCK_DEFINE_STATIC(name) extern void glib_dummy_decl (void)
 # define GPERL_REC_LOCK(name)
diff --git a/GType.xs b/GType.xs
index 6de570b..142eb55 100644
--- a/GType.xs
+++ b/GType.xs
@@ -1869,12 +1869,21 @@ gperl_type_base_init (gpointer class)
         * 
         * many thanks to Brett Kosinski for devising this evil^Wclever scheme.
         */
+#if GLIB_CHECK_VERSION (2, 32, 0)
+       /* GRecMutex in static storage do not need initialization */
+       static GRecMutex base_init_lock;
+#else
        static GStaticRecMutex base_init_lock = G_STATIC_REC_MUTEX_INIT;
+#endif /* 2.32 */
        static GHashTable * seen = NULL;
        GSList * types;
        GType t;
 
+#if GLIB_CHECK_VERSION (2, 32, 0)
+       g_rec_mutex_lock (&base_init_lock);
+#else
        g_static_rec_mutex_lock (&base_init_lock);
+#endif /* 2.32 */
 
        if (!seen)
                seen = g_hash_table_new (g_direct_hash, g_direct_equal);
@@ -1938,7 +1947,11 @@ gperl_type_base_init (gpointer class)
                }
        }
 
+#if GLIB_CHECK_VERSION (2, 32, 0)
+       g_rec_mutex_unlock (&base_init_lock);
+#else
        g_static_rec_mutex_unlock (&base_init_lock);
+#endif /* 2.32 */
 }
 
 /* make sure we close the open list to keep from freaking out pod readers... */
diff --git a/Glib.xs b/Glib.xs
index a709050..8466bb7 100644
--- a/Glib.xs
+++ b/Glib.xs
@@ -436,12 +436,16 @@ _gperl_get_main_tid (void)
 MODULE = Glib          PACKAGE = Glib          PREFIX = g_
 
 BOOT:
-#if defined(G_THREADS_ENABLED) && !defined(GPERL_DISABLE_THREADSAFE)
+#if !GLIB_CHECK_VERSION (2, 32, 0) && defined(G_THREADS_ENABLED) && !defined(GPERL_DISABLE_THREADSAFE)
+       /* g_thread_init() is a deprecated no-op */
        /*warn ("calling g_thread_init (NULL)");*/
        if (!g_thread_supported ())
                g_thread_init (NULL);
 #endif
+#if !GLIB_CHECK_VERSION (2, 36, 0)
+       /* g_type_init() is a deprecated no-op */
        g_type_init ();
+#endif
        _gperl_set_master_interp (PERL_GET_INTERP);
 #ifndef PERL_IMPLICIT_CONTEXT
        _gperl_fetch_main_tid ();


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