[gjs/wip/require: 172/175] context: Move gjs_get_search_path to here



commit 1a1a82ecfc1a01b5e686bac07940aa5655262783
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Jun 16 16:06:14 2015 -0700

    context: Move gjs_get_search_path to here
    
    We're soon going to remove the old importer system.

 gjs/context.cpp  |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 gjs/context.h    |    2 +
 gjs/importer.cpp |   55 ------------------------------------------------------
 gjs/importer.h   |    2 -
 4 files changed, 56 insertions(+), 57 deletions(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index ed11882..aaedb6f 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -798,3 +798,57 @@ gjs_context_get_search_path(GjsContext *context)
 {
     return (const char **) context->search_path;
 }
+
+G_CONST_RETURN char * G_CONST_RETURN *
+gjs_get_search_path(void)
+{
+    static char **gjs_search_path;
+    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);
+        }
+
+        g_ptr_array_add(path, g_strdup("resource:///org/gnome/gjs/modules/"));
+
+        /* $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);
+        }
+
+        /* ${datadir}/share/gjs-1.0 */
+        g_ptr_array_add(path, g_strdup(GJS_JS_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;
+}
diff --git a/gjs/context.h b/gjs/context.h
index acd07d1..54969a0 100644
--- a/gjs/context.h
+++ b/gjs/context.h
@@ -79,6 +79,8 @@ void            gjs_dumpstack                     (void);
 
 const char **   gjs_context_get_search_path       (GjsContext *context);
 
+G_CONST_RETURN char * G_CONST_RETURN * gjs_get_search_path (void);
+
 G_END_DECLS
 
 #endif  /* __GJS_CONTEXT_H__ */
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index e421dda..4765996 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -36,8 +36,6 @@
 
 #define MODULE_INIT_FILENAME "__init__.js"
 
-static char **gjs_search_path = NULL;
-
 typedef struct {
     gboolean is_root;
 } Importer;
@@ -997,59 +995,6 @@ importer_new(JSContext *context,
     return importer;
 }
 
-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);
-        }
-
-        g_ptr_array_add(path, g_strdup("resource:///org/gnome/gjs/modules/"));
-
-        /* $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);
-        }
-
-        /* ${datadir}/share/gjs-1.0 */
-        g_ptr_array_add(path, g_strdup(GJS_JS_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;
-}
-
 static JSObject*
 gjs_create_importer(JSContext    *context,
                     const char   *importer_name,
diff --git a/gjs/importer.h b/gjs/importer.h
index 8f11fb8..a3cea9f 100644
--- a/gjs/importer.h
+++ b/gjs/importer.h
@@ -45,8 +45,6 @@ JSObject* gjs_define_importer      (JSContext   *context,
                                     const char **initial_search_path,
                                     gboolean     add_standard_search_path);
 
-G_CONST_RETURN char * G_CONST_RETURN * gjs_get_search_path (void);
-
 G_END_DECLS
 
 #endif  /* __GJS_IMPORTER_H__ */


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