gobject-introspection r1024 - trunk/girepository



Author: walters
Date: Mon Jan 12 21:42:58 2009
New Revision: 1024
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=1024&view=rev

Log:
Bug 562914: Order GI_TYPELIB_PATH before anything else

We want the environment variable to override so that people can
easily write scripts that run their programs uninstalled.

Modified:
   trunk/girepository/girepository.c

Modified: trunk/girepository/girepository.c
==============================================================================
--- trunk/girepository/girepository.c	(original)
+++ trunk/girepository/girepository.c	Mon Jan 12 21:42:58 2009
@@ -37,6 +37,7 @@
 static GStaticMutex globals_lock = G_STATIC_MUTEX_INIT;
 static GIRepository *default_repository = NULL;
 static GSList *search_path = NULL;
+static GSList *override_search_path = NULL;
 
 struct _GIRepositoryPrivate 
 {
@@ -104,9 +105,13 @@
       char *typelib_dir;
       const gchar *type_lib_path_env;
 
+      /* This variable is intended to take precedence over both the default
+       * search path, as well as anything written into code with g_irepository_prepend_search_path.
+       */
       type_lib_path_env = g_getenv ("GI_TYPELIB_PATH");
 
       search_path = NULL;
+      override_search_path = NULL;
       if (type_lib_path_env)
         {
           gchar **custom_dirs;
@@ -117,7 +122,7 @@
           d = custom_dirs;
           while (*d)
             {
-              search_path = g_slist_prepend (search_path, *d);
+              override_search_path = g_slist_prepend (override_search_path, *d);
               d++;
             }
 
@@ -159,6 +164,21 @@
   return search_path;
 }
 
+static
+GSList *
+build_search_path_with_overrides (void)
+{
+	GSList *result;
+	if (override_search_path != NULL) 
+	  {
+		result = g_slist_copy (override_search_path);
+		g_slist_last (result)->next = g_slist_copy (search_path);
+	  } 
+	else
+	  result = g_slist_copy (search_path);
+	return result;
+}
+
 static char *
 build_typelib_key (const char *name, const char *source)
 {
@@ -843,6 +863,7 @@
 			const gchar  *version,
 			gchar       **path_ret)
 {
+  GSList *tmp_path;
   GSList *ldir;
   GError *error = NULL;
   GMappedFile *mfile = NULL;
@@ -850,7 +871,8 @@
  
   fname = g_strdup_printf ("%s-%s.typelib", namespace, version);
 
-  for (ldir = search_path; ldir; ldir = ldir->next)
+  tmp_path = build_search_path_with_overrides ();
+  for (ldir = tmp_path; ldir; ldir = ldir->next)
     {
       char *path = g_build_filename (ldir->data, fname, NULL);
       
@@ -865,6 +887,7 @@
       break;
     }
   g_free (fname);
+  g_slist_free (tmp_path);
   return mfile;
 }
 
@@ -963,6 +986,7 @@
 		       gchar       **version_ret,
 		       gchar       **path_ret)
 {
+  GSList *tmp_path;
   GSList *ldir;
   GError *error = NULL;
   char *namespace_dash;
@@ -978,7 +1002,8 @@
   namespace_typelib = g_strdup_printf ("%s.typelib", namespace);
 
   index = 0;
-  for (ldir = search_path; ldir; ldir = ldir->next)
+  tmp_path = build_search_path_with_overrides ();  
+  for (ldir = tmp_path; ldir; ldir = ldir->next)
     {
       GDir *dir;
       const char *dirname;
@@ -1048,9 +1073,9 @@
       g_slist_foreach (candidates, (GFunc) free_candidate, NULL);
       g_slist_free (candidates);
     }  
-
   g_free (namespace_dash);
   g_free (namespace_typelib);
+  g_slist_free (tmp_path);  
   return result;
 }
 



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