[gjs/wip/imports-rewrite: 4/5] context: Move gjs_get_search_path to here
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/imports-rewrite: 4/5] context: Move gjs_get_search_path to here
- Date: Wed, 17 Jun 2015 23:56:17 +0000 (UTC)
commit d4b8115affa6dd6c42b0073c83e6f1a54431c774
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Jun 17 16:38:06 2015 -0700
context: Move gjs_get_search_path to here
... and make it public. This will be used by the JS imports system,
since we'll be removing the old C++ one.
gjs/context.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
gjs/context.h | 2 +
gjs/importer.cpp | 55 ------------------------------------------------------
3 files changed, 56 insertions(+), 55 deletions(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 6564440..d1bd77c 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -792,3 +792,57 @@ gjs_get_import_global(JSContext *context)
GjsContext *gjs_context = (GjsContext *) JS_GetContextPrivate(context);
return gjs_context->global;
}
+
+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 ccd8bc6..175ccca 100644
--- a/gjs/context.h
+++ b/gjs/context.h
@@ -77,6 +77,8 @@ void gjs_context_gc (GjsContext *context);
void gjs_dumpstack (void);
+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 3b163e3..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;
}
-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);
- }
-
- 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]