[gcr] egg: Accomodate thread-safe libgcrypt 1.6+



commit a343d21ea4edc4435011f79e527a2c694f4ccc41
Author: Stef Walter <stefw gnome org>
Date:   Tue Sep 9 11:41:36 2014 +0200

    egg: Accomodate thread-safe libgcrypt 1.6+
    
    libcrypt no longer supports setting our own threading callbacks,
    and is thread-safe if we call gcry_check_version() before creating
    threads.
    
    Unfortunately we can't guarantee that we call gcry_check_version()
    early enough, we try our best. Most of the callers of Gcr either
    don't use libgcrypt, or also initialize it appropriately themselves.
    
    Bump libgcrypt dependency to 1.4.5+, and have earlier versions use
    the native pthread implementation of locking.

 configure.ac        |    3 ++-
 egg/egg-libgcrypt.c |   39 ++-------------------------------------
 2 files changed, 4 insertions(+), 38 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ee05920..d621230 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,6 +15,8 @@ GLIB_REQ=2.38.0
 GLIB_MIN=GLIB_VERSION_2_38
 GLIB_MAX=GLIB_VERSION_2_38
 
+GCRYPT_VERSION=1.4.5
+
 dnl ****************************************************************************
 dnl Library package and libtool versioning
 dnl
@@ -187,7 +189,6 @@ AC_DEFINE_UNQUOTED([GPG_EXECUTABLE], ["$GNUPG"], [Path to gpg executable.])
 # libgcrypt
 #
 
-GCRYPT_VERSION=1.2.2
 GCRYPT_LIBVER=1
 
 AM_PATH_LIBGCRYPT($GCRYPT_LIBVER:$GCRYPT_VERSION,,
diff --git a/egg/egg-libgcrypt.c b/egg/egg-libgcrypt.c
index eaa4240..e9a28b0 100644
--- a/egg/egg-libgcrypt.c
+++ b/egg/egg-libgcrypt.c
@@ -51,42 +51,7 @@ fatal_handler (gpointer unused, int unknown, const gchar *msg)
        g_log ("gcrypt", G_LOG_LEVEL_ERROR, "%s", msg);
 }
 
-static int
-glib_thread_mutex_init (void **lock)
-{
-       *lock = g_new0 (GMutex, 1);
-       g_mutex_init (*lock);
-       return 0;
-}
-
-static int
-glib_thread_mutex_destroy (void **lock)
-{
-       g_mutex_clear (*lock);
-       g_free (*lock);
-       return 0;
-}
-
-static int
-glib_thread_mutex_lock (void **lock)
-{
-       g_mutex_lock (*lock);
-       return 0;
-}
-
-static int
-glib_thread_mutex_unlock (void **lock)
-{
-       g_mutex_unlock (*lock);
-       return 0;
-}
-
-static struct gcry_thread_cbs glib_thread_cbs = {
-       GCRY_THREAD_OPTION_USER, NULL,
-       glib_thread_mutex_init, glib_thread_mutex_destroy,
-       glib_thread_mutex_lock, glib_thread_mutex_unlock,
-       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
-};
+GCRY_THREAD_OPTION_PTHREAD_IMPL;
 
 void
 egg_libgcrypt_initialize (void)
@@ -98,7 +63,7 @@ egg_libgcrypt_initialize (void)
 
                /* Only initialize libgcrypt if it hasn't already been initialized */
                if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) {
-                       gcry_control (GCRYCTL_SET_THREAD_CBS, &glib_thread_cbs);
+                       gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
                        gcry_check_version (LIBGCRYPT_VERSION);
                        gcry_set_log_handler (log_handler, NULL);
                        gcry_set_outofcore_handler (no_mem_handler, NULL);


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