gjs r43 - in trunk: . gi gjs util



Author: tko
Date: Fri Oct 24 10:12:15 2008
New Revision: 43
URL: http://svn.gnome.org/viewvc/gjs?rev=43&view=rev

Log:
Bug 557451 â Add search paths from environment variables

	* gjs/importer.c (gjs_get_search_path, gjs_define_importer):
	Simplify JS module search path to use only one environment
	variable (GJS_PATH) instead of three. JS modules are searched in
	order from $GJS_PATH:$XDG_DATA_DIRS/gjs-1.0:${libdir}/gjs-1.0

	* Makefile.am:
	* util/dirs.c:
	* util/dirs.h:
	* a/gi/repo.c: Remove dirs.[ch] as unused

Removed:
   trunk/util/dirs.c
   trunk/util/dirs.h
Modified:
   trunk/Makefile.am
   trunk/gi/repo.c
   trunk/gjs/importer.c

Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am	(original)
+++ trunk/Makefile.am	Fri Oct 24 10:12:15 2008
@@ -26,7 +26,6 @@
 	gjs/native.h
 noinst_HEADERS =		\
 	gjs/context-jsapi.h	\
-	util/dirs.h		\
 	util/error.h		\
 	util/glib.h		\
 	util/log.h		\
@@ -70,7 +69,6 @@
 	gjs/jsapi-util-string.c	\
 	gjs/mem.c		\
 	gjs/native.c		\
-	util/dirs.c		\
 	util/error.c		\
 	util/glib.c		\
 	util/log.c		\
@@ -80,7 +78,6 @@
 	gjs/jsapi-util-array.c	\
 	gjs/jsapi-util-error.c	\
 	gjs/jsapi-util-string.c	\
-	util/dirs.c		\
 	util/glib.c
 
 include Makefile-gi.am

Modified: trunk/gi/repo.c
==============================================================================
--- trunk/gi/repo.c	(original)
+++ trunk/gi/repo.c	Fri Oct 24 10:12:15 2008
@@ -34,7 +34,6 @@
 #include <gjs/mem.h>
 
 #include <util/log.h>
-#include <util/dirs.h>
 #include <util/misc.h>
 
 #include <jsapi.h>

Modified: trunk/gjs/importer.c
==============================================================================
--- trunk/gjs/importer.c	(original)
+++ trunk/gjs/importer.c	Fri Oct 24 10:12:15 2008
@@ -24,7 +24,6 @@
 #include <config.h>
 
 #include <util/log.h>
-#include <util/dirs.h>
 #include <util/glib.h>
 
 #include <jsapi.h>
@@ -36,6 +35,8 @@
 
 #include <string.h>
 
+static char **gjs_search_path = NULL;
+
 typedef struct {
     void *dummy;
 } Importer;
@@ -820,6 +821,57 @@
     return importer;
 }
 
+static G_CONST_RETURN char * G_CONST_RETURN *
+gjs_get_search_path(void)
+{
+    char **search_path;
+
+    /* not thread safe */
+
+    if (!gjs_search_path) {
+        G_CONST_RETURN gchar* G_CONST_RETURN * system_data_dirs;
+        const char *envstr;
+        GPtrArray *path;
+        gsize i;
+
+        path = g_ptr_array_new();
+
+        /* in order of priority */
+
+        /* $GJS_PATH */
+        envstr = g_getenv("GJS_PATH");
+        if (envstr) {
+            char **dirs, **d;
+            dirs = g_strsplit(envstr, G_SEARCHPATH_SEPARATOR_S, 0);
+            for (d = dirs; *d != NULL; d++)
+                g_ptr_array_add(path, *d);
+            /* we assume the array and strings are allocated separately */
+            g_free(dirs);
+        }
+
+        /* $XDG_DATA_DIRS /gjs-1.0 */
+        system_data_dirs = g_get_system_data_dirs();
+        for (i = 0; system_data_dirs[i] != NULL; ++i) {
+            char *s;
+            s = g_build_filename(system_data_dirs[i], "gjs-1.0", NULL);
+            g_ptr_array_add(path, s);
+        }
+
+        /* ${libdir}/gjs-1.0 */
+        g_ptr_array_add(path, g_strdup(GJS_NATIVE_DIR));
+
+        g_ptr_array_add(path, NULL);
+
+        search_path = (char**)g_ptr_array_free(path, FALSE);
+
+        gjs_search_path = search_path;
+    } else {
+        search_path = gjs_search_path;
+    }
+
+    return (G_CONST_RETURN char * G_CONST_RETURN *)search_path;
+}
+
 JSObject*
 gjs_define_importer(JSContext    *context,
                     JSObject     *in_object,
@@ -828,19 +880,16 @@
                     gboolean      add_standard_search_path)
 {
     JSObject *importer;
-    char **paths[3] = {0};
+    char **paths[2] = {0};
     char **search_path;
 
     paths[0] = (char**)initial_search_path;
     if (add_standard_search_path) {
         /* Stick the "standard" shared search path after the provided one. */
-        paths[1] = gjs_get_search_path(GJS_DIRECTORY_SHARED_JAVASCRIPT);
-        paths[2] = gjs_get_search_path(GJS_DIRECTORY_SHARED_JAVASCRIPT_NATIVE);
+        paths[1] = (char**)gjs_get_search_path();
     }
 
-    search_path = gjs_g_strv_concat(paths, 3);
-    g_strfreev(paths[1]);
-    g_strfreev(paths[2]);
+    search_path = gjs_g_strv_concat(paths, 2);
 
     importer = importer_new(context);
 



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