[gnome-keyring] Fix for deprecations in glib 2.31.x



commit bde64e94f83a6da4eaff6503744e200c9f1f0081
Author: Stef Walter <stefw collabora co uk>
Date:   Tue Dec 6 16:49:39 2011 +0100

    Fix for deprecations in glib 2.31.x
    
     * Mainly g_mutex_new/g_mutex_free g_cond_new/g_cond_free
     * Since we like to build with the last stable version of glib,
       using #ifdef until these glib changes make it into a stable release.

 daemon/gkd-main.c                           |    1 -
 daemon/gpg-agent/gkd-gpg-agent-standalone.c |    3 -
 daemon/gpg-agent/gkd-gpg-agent.c            |   18 +++++
 daemon/ssh-agent/gkd-ssh-agent-standalone.c |    3 -
 daemon/ssh-agent/gkd-ssh-agent.c            |   18 +++++
 egg/egg-libgcrypt.c                         |   10 +++
 egg/egg-testing.c                           |   90 +++++++++++++++++++++-----
 pkcs11/gkm/gkm-timer.c                      |   45 +++++++++++---
 pkcs11/gnome2-store/gkm-gnome2-standalone.c |    2 -
 pkcs11/roots-store/gkm-roots-standalone.c   |    3 -
 pkcs11/rpc-layer/gkm-rpc-dispatch.c         |    4 +
 pkcs11/secret-store/gkm-secret-standalone.c |    3 -
 pkcs11/ssh-store/gkm-ssh-standalone.c       |    2 -
 pkcs11/xdg-store/gkm-xdg-standalone.c       |    2 -
 tool/gkr-tool.c                             |    3 +-
 ui/gku-prompt.c                             |   14 ++++-
 16 files changed, 172 insertions(+), 49 deletions(-)
---
diff --git a/daemon/gkd-main.c b/daemon/gkd-main.c
index 12d3de9..e9f4392 100644
--- a/daemon/gkd-main.c
+++ b/daemon/gkd-main.c
@@ -882,7 +882,6 @@ main (int argc, char *argv[])
 #endif
 
 	g_type_init ();
-	g_thread_init (NULL);
 
 #ifdef HAVE_LOCALE_H
 	/* internationalisation */
diff --git a/daemon/gpg-agent/gkd-gpg-agent-standalone.c b/daemon/gpg-agent/gkd-gpg-agent-standalone.c
index c573e47..a9a1c99 100644
--- a/daemon/gpg-agent/gkd-gpg-agent-standalone.c
+++ b/daemon/gpg-agent/gkd-gpg-agent-standalone.c
@@ -79,9 +79,6 @@ main(int argc, char *argv[])
 
 	g_type_init ();
 
-	if (!g_thread_supported ())
-		g_thread_init (NULL);
-
 	if (argc <= 1) {
 		g_message ("specify pkcs11 module on the command line");
 		return 1;
diff --git a/daemon/gpg-agent/gkd-gpg-agent.c b/daemon/gpg-agent/gkd-gpg-agent.c
index 7e4aaf8..0365c21 100644
--- a/daemon/gpg-agent/gkd-gpg-agent.c
+++ b/daemon/gpg-agent/gkd-gpg-agent.c
@@ -329,7 +329,11 @@ gkd_gpg_agent_accept (void)
 	client->sock = new_fd;
 
 	/* And create a new thread/process */
+#if GLIB_CHECK_VERSION(2,31,2)
+	client->thread = g_thread_new ("gpg-agent", run_client_thread, &client->sock);
+#else
 	client->thread = g_thread_create (run_client_thread, &client->sock, TRUE, &error);
+#endif
 	if (!client->thread) {
 		g_warning ("couldn't create thread GPG agent connection: %s",
 		           error && error->message ? error->message : "");
@@ -385,8 +389,15 @@ gkd_gpg_agent_uninitialize (void)
 		pkcs11_main_session = NULL;
 
 	g_mutex_unlock (pkcs11_main_mutex);
+#if GLIB_CHECK_VERSION(2,31,2)
+	g_mutex_clear (pkcs11_main_mutex);
+	g_free (pkcs11_main_mutex);
+	g_cond_clear (pkcs11_main_cond);
+	g_free (pkcs11_main_cond);
+#else
 	g_mutex_free (pkcs11_main_mutex);
 	g_cond_free (pkcs11_main_cond);
+#endif
 
 	g_assert (pkcs11_module);
 	g_object_unref (pkcs11_module);
@@ -446,8 +457,15 @@ gkd_gpg_agent_initialize_with_module (GckModule *module)
 
 	pkcs11_module = g_object_ref (module);
 
+#if GLIB_CHECK_VERSION(2,31,2)
+	pkcs11_main_mutex = g_new0 (GMutex, 1);
+	g_mutex_init (pkcs11_main_mutex);
+	pkcs11_main_cond = g_new0 (GCond, 1);
+	g_cond_init (pkcs11_main_cond);
+#else
 	pkcs11_main_mutex = g_mutex_new ();
 	pkcs11_main_cond = g_cond_new ();
+#endif
 	pkcs11_main_checked = FALSE;
 	pkcs11_main_session = session;
 
diff --git a/daemon/ssh-agent/gkd-ssh-agent-standalone.c b/daemon/ssh-agent/gkd-ssh-agent-standalone.c
index 5879d17..a496a36 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-standalone.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-standalone.c
@@ -80,9 +80,6 @@ main(int argc, char *argv[])
 
 	g_type_init ();
 
-	if (!g_thread_supported ())
-		g_thread_init (NULL);
-
 	if (argc <= 1) {
 		g_message ("specify pkcs11 module on the command line");
 		return 1;
diff --git a/daemon/ssh-agent/gkd-ssh-agent.c b/daemon/ssh-agent/gkd-ssh-agent.c
index 2f83631..7ac1cc9 100644
--- a/daemon/ssh-agent/gkd-ssh-agent.c
+++ b/daemon/ssh-agent/gkd-ssh-agent.c
@@ -284,7 +284,11 @@ gkd_ssh_agent_accept (void)
 	client->sock = new_fd;
 
 	/* And create a new thread/process */
+#if GLIB_CHECK_VERSION(2,31,3)
+	client->thread = g_thread_new ("ssh-agent", run_client_thread, &client->sock);
+#else
 	client->thread = g_thread_create (run_client_thread, &client->sock, TRUE, &error);
+#endif
 	if (!client->thread) {
 		g_warning ("couldn't create thread SSH agent connection: %s",
 		           egg_error_message (error));
@@ -340,8 +344,15 @@ gkd_ssh_agent_uninitialize (void)
 		pkcs11_main_session = NULL;
 
 	g_mutex_unlock (pkcs11_main_mutex);
+#if GLIB_CHECK_VERSION(2,31,3)
+	g_mutex_clear (pkcs11_main_mutex);
+	g_free (pkcs11_main_mutex);
+	g_cond_clear (pkcs11_main_cond);
+	g_free (pkcs11_main_cond);
+#else
 	g_mutex_free (pkcs11_main_mutex);
 	g_cond_free (pkcs11_main_cond);
+#endif
 
 	gck_list_unref_free (pkcs11_modules);
 	pkcs11_modules = NULL;
@@ -400,8 +411,15 @@ gkd_ssh_agent_initialize_with_module (GckModule *module)
 	g_assert (!pkcs11_modules);
 	pkcs11_modules = g_list_append (NULL, g_object_ref (module));
 
+#if GLIB_CHECK_VERSION(2,31,3)
+	pkcs11_main_mutex = g_new0 (GMutex, 1);
+	g_mutex_init (pkcs11_main_mutex);
+	pkcs11_main_cond = g_new0 (GCond, 1);
+	g_cond_init (pkcs11_main_cond);
+#else
 	pkcs11_main_mutex = g_mutex_new ();
 	pkcs11_main_cond = g_cond_new ();
+#endif
 	pkcs11_main_checked = FALSE;
 	pkcs11_main_session = session;
 
diff --git a/egg/egg-libgcrypt.c b/egg/egg-libgcrypt.c
index e5b3f55..6341163 100644
--- a/egg/egg-libgcrypt.c
+++ b/egg/egg-libgcrypt.c
@@ -56,14 +56,24 @@ fatal_handler (gpointer unused, int unknown, const gchar *msg)
 static int
 glib_thread_mutex_init (void **lock)
 {
+#if GLIB_CHECK_VERSION(2,31,3)
+	*lock = g_new0 (GMutex, 1);
+	g_mutex_init (*lock);
+#else
 	*lock = g_mutex_new ();
+#endif
 	return 0;
 }
 
 static int 
 glib_thread_mutex_destroy (void **lock)
 {
+#if GLIB_CHECK_VERSION(2,31,3)
+	g_mutex_clear (*lock);
+	g_free (*lock);
+#else
 	g_mutex_free (*lock);
+#endif
 	return 0;
 }
 
diff --git a/egg/egg-testing.c b/egg/egg-testing.c
index 0235ac0..0269af6 100644
--- a/egg/egg-testing.c
+++ b/egg/egg-testing.c
@@ -28,9 +28,16 @@
 #include <errno.h>
 #include <unistd.h>
 
+#if GLIB_CHECK_VERSION(2,31,3)
+static GCond wait_condition;
+static GCond wait_start;
+static GMutex wait_mutex;
+#else
 static GCond *wait_condition = NULL;
 static GCond *wait_start = NULL;
 static GMutex *wait_mutex = NULL;
+#endif
+
 static gboolean wait_waiting = FALSE;
 
 static const char HEXC[] = "0123456789ABCDEF";
@@ -82,40 +89,73 @@ egg_assertion_message_cmpmem (const char     *domain,
 void
 egg_test_wait_stop (void)
 {
-	GTimeVal tv;
-
-	g_get_current_time (&tv);
-	g_time_val_add (&tv, 1000);
-
+#if GLIB_CHECK_VERSION(2,31,3)
+	g_mutex_lock (&wait_mutex);
+#else
 	g_assert (wait_mutex);
 	g_assert (wait_condition);
 	g_mutex_lock (wait_mutex);
-		if (!wait_waiting)
-			g_cond_timed_wait (wait_start, wait_mutex, &tv);
-		g_assert (wait_waiting);
-		g_cond_broadcast (wait_condition);
+#endif
+
+	if (!wait_waiting) {
+#if GLIB_CHECK_VERSION(2,31,3)
+		gint64 time = g_get_monotonic_time () + 1 * G_TIME_SPAN_SECOND;
+		g_cond_wait_until (&wait_start, &wait_mutex, time);
+#else
+		GTimeVal tv;
+		g_get_current_time (&tv);
+		g_time_val_add (&tv, 1000);
+		g_cond_timed_wait (wait_start, wait_mutex, &tv);
+#endif
+	}
+	g_assert (wait_waiting);
+
+#if GLIB_CHECK_VERSION(2,31,3)
+	g_cond_broadcast (&wait_condition);
+	g_mutex_unlock (&wait_mutex);
+#else
+	g_cond_broadcast (wait_condition);
 	g_mutex_unlock (wait_mutex);
+#endif
 }
 
 gboolean
 egg_test_wait_until (int timeout)
 {
-	GTimeVal tv;
 	gboolean ret;
 
-	g_get_current_time (&tv);
-	g_time_val_add (&tv, timeout * 1000);
-
+#if GLIB_CHECK_VERSION(2,31,3)
+	g_mutex_lock (&wait_mutex);
+#else
 	g_assert (wait_mutex);
 	g_assert (wait_condition);
 	g_mutex_lock (wait_mutex);
-		g_assert (!wait_waiting);
-		wait_waiting = TRUE;
+#endif
+
+	g_assert (!wait_waiting);
+	wait_waiting = TRUE;
+
+	{
+#if GLIB_CHECK_VERSION(2,31,3)
+		gint64 time = g_get_monotonic_time () + ((timeout + 1000) * G_TIME_SPAN_MILLISECOND);
+		g_cond_broadcast (&wait_start);
+		ret = g_cond_wait_until (&wait_start, &wait_mutex, time);
+#else
+		GTimeVal tv;
+		g_get_current_time (&tv);
+		g_time_val_add (&tv, timeout * 1000);
 		g_cond_broadcast (wait_start);
 		ret = g_cond_timed_wait (wait_condition, wait_mutex, &tv);
-		g_assert (wait_waiting);
-		wait_waiting = FALSE;
+#endif
+	}
+
+	g_assert (wait_waiting);
+	wait_waiting = FALSE;
+#if GLIB_CHECK_VERSION(2,31,3)
+	g_mutex_unlock (&wait_mutex);
+#else
 	g_mutex_unlock (wait_mutex);
+#endif
 
 	return ret;
 }
@@ -136,22 +176,36 @@ egg_tests_run_in_thread_with_loop (void)
 	GMainLoop *loop;
 	gpointer ret;
 
+#if !GLIB_CHECK_VERSION(2,31,3)
 	g_thread_init (NULL);
+#endif
 
 	loop = g_main_loop_new (NULL, FALSE);
+#if GLIB_CHECK_VERSION(2,31,3)
+	g_cond_init (&wait_condition);
+	g_cond_init (&wait_start);
+	g_mutex_init (&wait_mutex);
+	thread = g_thread_new ("testing", testing_thread, loop);
+#else
 	wait_condition = g_cond_new ();
 	wait_start = g_cond_new ();
 	wait_mutex = g_mutex_new ();
-
 	thread = g_thread_create (testing_thread, loop, TRUE, NULL);
+#endif
+
 	g_assert (thread);
 
 	g_main_loop_run (loop);
 	ret = g_thread_join (thread);
 	g_main_loop_unref (loop);
 
+#if GLIB_CHECK_VERSION(2,31,2)
+	g_cond_clear (&wait_condition);
+	g_mutex_clear (&wait_mutex);
+#else
 	g_cond_free (wait_condition);
 	g_mutex_free (wait_mutex);
+#endif
 
 	return GPOINTER_TO_INT (ret);
 }
diff --git a/pkcs11/gkm/gkm-timer.c b/pkcs11/gkm/gkm-timer.c
index bde8ce1..f747975 100644
--- a/pkcs11/gkm/gkm-timer.c
+++ b/pkcs11/gkm/gkm-timer.c
@@ -38,6 +38,9 @@ struct _GkmTimer {
 static GStaticMutex timer_mutex = G_STATIC_MUTEX_INIT;
 static GQueue *timer_queue = NULL;
 static GThread *timer_thread = NULL;
+#if GLIB_CHECK_VERSION(2,31,3)
+static GCond timer_condition;
+#endif
 static GCond *timer_cond = NULL;
 static gboolean timer_run = FALSE;
 static gint timer_refs = 0;
@@ -57,7 +60,6 @@ timer_thread_func (gpointer unused)
 {
 	GMutex *mutex = g_static_mutex_get_mutex (&timer_mutex);
 	GkmTimer *timer;
-	GTimeVal tv;
 
 	g_mutex_lock (mutex);
 
@@ -70,14 +72,26 @@ timer_thread_func (gpointer unused)
 			continue;
 		}
 
-		g_get_current_time (&tv);
-
-		/* We have to wait until the next timer? */
-		if (tv.tv_sec < timer->when) {
-			tv.tv_sec = timer->when;
-			tv.tv_usec = 0;
-			g_cond_timed_wait (timer_cond, mutex, &tv);
-			continue;
+		if (timer->when) {
+#if GLIB_CHECK_VERSION(2,31,3)
+			gint64 when = ((gint64)timer->when) * G_TIME_SPAN_SECOND;
+			gint64 offset = when - g_get_real_time ();
+			if (offset > 0) {
+				g_cond_wait_until (timer_cond, mutex, g_get_monotonic_time () + offset);
+				continue;
+			}
+#else
+			GTimeVal tv;
+			g_get_current_time (&tv);
+
+			/* We have to wait until the next timer? */
+			if (tv.tv_sec < timer->when) {
+				tv.tv_sec = timer->when;
+				tv.tv_usec = 0;
+				g_cond_timed_wait (timer_cond, mutex, &tv);
+				continue;
+			}
+#endif
 		}
 
 		/* Leave our thread mutex, and enter the module */
@@ -109,13 +123,22 @@ gkm_timer_initialize (void)
 		g_atomic_int_inc (&timer_refs);
 		if (!timer_thread) {
 			timer_run = TRUE;
+#if GLIB_CHECK_VERSION(2,31,3)
+			timer_thread = g_thread_new ("timer", timer_thread_func, NULL);
+#else
 			timer_thread = g_thread_create (timer_thread_func, NULL, TRUE, &error);
+#endif
 			if (timer_thread) {
 				g_assert (timer_queue == NULL);
 				timer_queue = g_queue_new ();
 
 				g_assert (timer_cond == NULL);
+#if GLIB_CHECK_VERSION(2,31,3)
+				timer_cond = &timer_condition;
+				g_cond_init (timer_cond);
+#else
 				timer_cond = g_cond_new ();
+#endif
 			} else {
 				g_warning ("could not create timer thread: %s",
 				           egg_error_message (error));
@@ -155,7 +178,11 @@ gkm_timer_shutdown (void)
 		g_queue_free (timer_queue);
 		timer_queue = NULL;
 
+#if GLIB_CHECK_VERSION(2,31,3)
+		g_cond_clear (timer_cond);
+#else
 		g_cond_free (timer_cond);
+#endif
 		timer_cond = NULL;
 	}
 }
diff --git a/pkcs11/gnome2-store/gkm-gnome2-standalone.c b/pkcs11/gnome2-store/gkm-gnome2-standalone.c
index 21ad2c6..631499c 100644
--- a/pkcs11/gnome2-store/gkm-gnome2-standalone.c
+++ b/pkcs11/gnome2-store/gkm-gnome2-standalone.c
@@ -43,8 +43,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
 		return CKR_ARGUMENTS_BAD;
 
 	g_type_init ();
-	if (!g_thread_supported ())
-		g_thread_init (NULL);
 
 	*list = gkm_gnome2_store_get_functions ();
 	return CKR_OK;
diff --git a/pkcs11/roots-store/gkm-roots-standalone.c b/pkcs11/roots-store/gkm-roots-standalone.c
index 469fb15..fb0f642 100644
--- a/pkcs11/roots-store/gkm-roots-standalone.c
+++ b/pkcs11/roots-store/gkm-roots-standalone.c
@@ -59,9 +59,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
 
 	g_type_init ();
 
-	if (!g_thread_supported ())
-		g_thread_init (NULL);
-
 	gkm_crypto_initialize ();
 
 	*list = gkm_roots_store_get_functions ();
diff --git a/pkcs11/rpc-layer/gkm-rpc-dispatch.c b/pkcs11/rpc-layer/gkm-rpc-dispatch.c
index a32043d..d187148 100644
--- a/pkcs11/rpc-layer/gkm-rpc-dispatch.c
+++ b/pkcs11/rpc-layer/gkm-rpc-dispatch.c
@@ -2229,7 +2229,11 @@ gkm_rpc_layer_accept (void)
 
 	ds->socket = new_fd;
 
+#if GLIB_CHECK_VERSION(2,31,3)
+	ds->thread = g_thread_new ("dispatch", run_dispatch_thread, &(ds->socket));
+#else
 	ds->thread = g_thread_create (run_dispatch_thread, &(ds->socket), TRUE, &error);
+#endif
 	if (!ds->thread) {
 		gkm_rpc_warn ("couldn't start thread: %s", egg_error_message (error));
 		close (new_fd);
diff --git a/pkcs11/secret-store/gkm-secret-standalone.c b/pkcs11/secret-store/gkm-secret-standalone.c
index 56b54e6..70924b9 100644
--- a/pkcs11/secret-store/gkm-secret-standalone.c
+++ b/pkcs11/secret-store/gkm-secret-standalone.c
@@ -59,9 +59,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
 
 	g_type_init ();
 
-	if (!g_thread_supported ())
-		g_thread_init (NULL);
-
 	gkm_crypto_initialize ();
 
 	*list = gkm_secret_store_get_functions ();
diff --git a/pkcs11/ssh-store/gkm-ssh-standalone.c b/pkcs11/ssh-store/gkm-ssh-standalone.c
index a15bf0e..0d7c10d 100644
--- a/pkcs11/ssh-store/gkm-ssh-standalone.c
+++ b/pkcs11/ssh-store/gkm-ssh-standalone.c
@@ -58,8 +58,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
 		return CKR_ARGUMENTS_BAD;
 
 	g_type_init ();
-	if (!g_thread_supported ())
-		g_thread_init (NULL);
 
 	*list = gkm_ssh_store_get_functions ();
 	return CKR_OK;
diff --git a/pkcs11/xdg-store/gkm-xdg-standalone.c b/pkcs11/xdg-store/gkm-xdg-standalone.c
index dc46dc2..dd1d328 100644
--- a/pkcs11/xdg-store/gkm-xdg-standalone.c
+++ b/pkcs11/xdg-store/gkm-xdg-standalone.c
@@ -58,8 +58,6 @@ C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
 		return CKR_ARGUMENTS_BAD;
 
 	g_type_init ();
-	if (!g_thread_supported ())
-		g_thread_init (NULL);
 
 	*list = gkm_xdg_store_get_functions ();
 	return CKR_OK;
diff --git a/tool/gkr-tool.c b/tool/gkr-tool.c
index 73aac6d..f783802 100644
--- a/tool/gkr-tool.c
+++ b/tool/gkr-tool.c
@@ -116,8 +116,7 @@ main (int argc, char *argv[])
 	int ret = -1;
 	
 	g_type_init ();
-	g_thread_init (NULL);
-	
+
 #ifdef HAVE_LOCALE_H
 	/* internationalisation */
 	setlocale (LC_ALL, "");
diff --git a/ui/gku-prompt.c b/ui/gku-prompt.c
index 0a72424..c809272 100644
--- a/ui/gku-prompt.c
+++ b/ui/gku-prompt.c
@@ -1093,7 +1093,15 @@ gku_prompt_request_attention_sync (const gchar *window_id, GkuPromptAttentionFun
                                    gpointer user_data, GDestroyNotify destroy_notify)
 {
 	AttentionReq *att = prepare_attention_req (window_id, callback, user_data, destroy_notify);
-	GCond *cond = g_cond_new ();
+	GCond *cond;
+
+#if GLIB_CHECK_VERSION(2,31,3)
+	GCond condition;
+	g_cond_init (&condition);
+	cond = &condition;
+#else
+	cond = g_cond_new ();
+#endif
 
 	g_return_if_fail (att);
 	att->cond = cond;
@@ -1106,7 +1114,11 @@ gku_prompt_request_attention_sync (const gchar *window_id, GkuPromptAttentionFun
 		g_cond_wait (cond, g_static_mutex_get_mutex (&attention_mutex));
 	g_static_mutex_unlock (&attention_mutex);
 
+#if GLIB_CHECK_VERSION(2,31,3)
+	g_cond_clear (&condition);
+#else
 	g_cond_free (cond);
+#endif
 }
 
 #ifdef WITH_TESTABLE



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