[glade] Let g_module_open() be called with NULL so that it looks libraries in defaults directories Fixes bug



commit c50a7358e686655234c4693690815c58f81052e2
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Thu May 17 23:28:47 2012 -0300

    Let g_module_open() be called with NULL so that it looks libraries in defaults directories
    Fixes bug #675977 "Don't hard-code library search paths"

 gladeui/Makefile.am   |    3 ++-
 gladeui/glade-app.c   |   12 ++++++++++++
 gladeui/glade-app.h   |    1 +
 gladeui/glade-utils.c |   41 +++++++++++++++--------------------------
 4 files changed, 30 insertions(+), 27 deletions(-)
---
diff --git a/gladeui/Makefile.am b/gladeui/Makefile.am
index 7563f99..7aa5367 100644
--- a/gladeui/Makefile.am
+++ b/gladeui/Makefile.am
@@ -40,7 +40,8 @@ common_defines = \
 	-DGLADE_MODULESDIR="\"$(pkglibdir)/modules\""	\
 	-DGLADE_PIXMAPSDIR="\"$(pkgdatadir)/pixmaps\""	\
 	-DGLADE_LOCALEDIR="\"$(datadir)/locale\""\
-	-DGLADE_BINDIR="\"$(bindir)\""
+	-DGLADE_BINDIR="\"$(bindir)\""\
+	-DGLADE_LIBDIR="\"$(libdir)\""
 
 BUILT_SOURCES = glade-marshallers.c glade-marshallers.h
 
diff --git a/gladeui/glade-app.c b/gladeui/glade-app.c
index 622b33e..fd1bedb 100644
--- a/gladeui/glade-app.c
+++ b/gladeui/glade-app.c
@@ -85,6 +85,7 @@ static gchar *modules_dir = NULL;
 static gchar *pixmaps_dir = NULL;
 static gchar *locale_dir = NULL;
 static gchar *bin_dir = NULL;
+static gchar *lib_dir = NULL;
 
 static GladeApp *singleton_app = NULL;
 static gboolean check_initialised = FALSE;
@@ -148,6 +149,7 @@ glade_app_finalize (GObject * app)
   g_free (pixmaps_dir);
   g_free (locale_dir);
   g_free (bin_dir);
+  g_free (lib_dir);
 
   singleton_app = NULL;
   check_initialised = FALSE;
@@ -175,6 +177,7 @@ build_package_paths (void)
   modules_dir = g_build_filename (prefix, "lib", PACKAGE, "modules", NULL);
   locale_dir = g_build_filename (prefix, "share", "locale", NULL);
   bin_dir = g_build_filename (prefix, "bin", NULL);
+  lib_dir = g_build_filename (prefix, "lib", NULL);
 
   g_free (prefix);
 #else
@@ -183,6 +186,7 @@ build_package_paths (void)
   pixmaps_dir = g_strdup (GLADE_PIXMAPSDIR);
   locale_dir = g_strdup (GLADE_LOCALEDIR);
   bin_dir = g_strdup (GLADE_BINDIR);
+  lib_dir = g_strdup (GLADE_LIBDIR);
 #endif
 }
 
@@ -247,6 +251,14 @@ glade_app_get_bin_dir (void)
   return bin_dir;
 }
 
+const gchar *
+glade_app_get_lib_dir (void)
+{
+  glade_init_check ();
+
+  return lib_dir;
+}
+
 static void
 pointer_mode_register_icon (GtkIconFactory *factory,
                             const gchar *icon_name,
diff --git a/gladeui/glade-app.h b/gladeui/glade-app.h
index d0f06fa..6b3e4b3 100644
--- a/gladeui/glade-app.h
+++ b/gladeui/glade-app.h
@@ -102,6 +102,7 @@ const gchar       *glade_app_get_plugins_dir      (void) G_GNUC_CONST;
 const gchar       *glade_app_get_pixmaps_dir      (void) G_GNUC_CONST;
 const gchar       *glade_app_get_locale_dir       (void) G_GNUC_CONST;
 const gchar       *glade_app_get_bin_dir          (void) G_GNUC_CONST;
+const gchar       *glade_app_get_lib_dir          (void) G_GNUC_CONST;
 
 G_END_DECLS
 
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index fb00f9d..8d85118 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -869,8 +869,8 @@ try_load_library (const gchar *library_path, const gchar *library_name)
  * glade_util_load_library:
  * @library_name: name of the library
  *
- * Loads the named library from the Glade modules directory, or failing that
- * from the standard platform specific directories.
+ * Loads the named library from the Glade modules and lib directory or failing that
+ * from the standard platform specific directories. (Including /usr/local/lib for unices)
  *
  * The @library_name should not include any platform specifix prefix or suffix,
  * those are automatically added, if needed, by g_module_build_path()
@@ -880,23 +880,23 @@ try_load_library (const gchar *library_path, const gchar *library_name)
 GModule *
 glade_util_load_library (const gchar *library_name)
 {
-  gchar *default_paths[] = { (gchar *) glade_app_get_modules_dir (),
-    NULL,                       /* <-- dynamically allocated */
-    "/lib",
-    "/usr/lib",
-    "/usr/local/lib",
-    NULL
-  };
-
+  const gchar *paths[] =
+    {
+      glade_app_get_modules_dir (),
+      glade_app_get_lib_dir (),
+#ifndef G_OS_WIN32
+      "/usr/local/lib", /* Try local lib dir on Unices */
+#endif
+      NULL /* Use default system paths */
+    };
   GModule *module = NULL;
   const gchar *search_path;
-  gchar **split;
   gint i;
 
-
-
   if ((search_path = g_getenv (GLADE_ENV_MODULE_PATH)) != NULL)
     {
+      gchar **split;
+
       if ((split = g_strsplit (search_path, ":", 0)) != NULL)
         {
           for (i = 0; split[i] != NULL; i++)
@@ -909,22 +909,11 @@ glade_util_load_library (const gchar *library_name)
 
   if (!module)
     {
-      /* Search ${prefix}/lib after searching ${prefix}/lib/glade3/modules... */
-      default_paths[1] =
-          g_build_filename (glade_app_get_modules_dir (), "..", "..", NULL);
-
-      for (i = 0; default_paths[i] != NULL; i++)
-        if ((module =
-             try_load_library (default_paths[i], library_name)) != NULL)
+      for (i = 0; i < G_N_ELEMENTS (paths); i++)
+        if ((module = try_load_library (paths[i], library_name)) != NULL)
           break;
-
-      g_free (default_paths[1]);
     }
 
-  if (!module)
-    g_critical ("Unable to load module '%s' from any search paths",
-                library_name);
-
   return module;
 }
 



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