[gjs] importer: Remove support for loading external native modules



commit aa9fb97b5959781f81e1a238f991c8abc75f36ca
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Feb 27 18:40:22 2013 -0500

    importer: Remove support for loading external native modules
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694873

 gjs/importer.c |   34 +++++-----------------------------
 gjs/native.c   |   38 ++++----------------------------------
 gjs/native.h   |   10 +++-------
 3 files changed, 12 insertions(+), 70 deletions(-)
---
diff --git a/gjs/importer.c b/gjs/importer.c
index 001a252..dde1ce1 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -231,14 +231,12 @@ cancel_import(JSContext  *context,
 static JSBool
 import_native_file(JSContext  *context,
                    JSObject   *obj,
-                   const char *name,
-                   const char *full_path)
+                   const char *name)
 {
     JSObject *module_obj;
     JSBool retval = JS_FALSE;
 
-    gjs_debug(GJS_DEBUG_IMPORTER,
-              "Importing '%s' from '%s'", name, full_path ? full_path : "<internal>");
+    gjs_debug(GJS_DEBUG_IMPORTER, "Importing '%s'", name);
 
     module_obj = JS_NewObject(context, NULL, NULL, NULL);
     if (module_obj == NULL) {
@@ -253,10 +251,10 @@ import_native_file(JSContext  *context,
     if (!define_import(context, obj, module_obj, name))
         return JS_FALSE;
 
-    if (!define_meta_properties(context, module_obj, full_path, name, obj))
+    if (!define_meta_properties(context, module_obj, NULL, name, obj))
         goto out;
 
-    if (!gjs_import_native_module(context, module_obj, full_path))
+    if (!gjs_import_native_module(context, module_obj))
         goto out;
 
     if (!finish_import(context, name))
@@ -495,7 +493,6 @@ do_import(JSContext  *context,
           const char *name)
 {
     char *filename;
-    char *native_filename;
     char *full_path;
     char *dirname = NULL;
     jsval search_path_val;
@@ -534,13 +531,12 @@ do_import(JSContext  *context,
     result = JS_FALSE;
 
     filename = g_strdup_printf("%s.js", name);
-    native_filename = g_strdup_printf("%s."G_MODULE_SUFFIX, name);
     full_path = NULL;
     directories = NULL;
 
     /* First try importing an internal module like byteArray */
     if (gjs_is_registered_native_module(context, obj, name) &&
-        import_native_file(context, obj, name, NULL)) {
+        import_native_file(context, obj, name)) {
         gjs_debug(GJS_DEBUG_IMPORTER,
                   "successfully imported module '%s'", name);
         result = JS_TRUE;
@@ -648,25 +644,6 @@ do_import(JSContext  *context,
             goto out;
         }
 
-        /* Finally see if it's a native module */
-        g_free(full_path);
-        full_path = g_build_filename(dirname, native_filename,
-                                     NULL);
-
-        if (g_file_test(full_path, G_FILE_TEST_EXISTS)) {
-            if (import_native_file(context, obj, name, full_path)) {
-                gjs_debug(GJS_DEBUG_IMPORTER,
-                          "successfully imported module '%s'", name);
-                result = JS_TRUE;
-            }
-
-            /* Don't keep searching path if we fail to load the file for
-             * reasons other than it doesn't exist... i.e. broken files
-             * block searching for nonbroken ones
-             */
-            goto out;
-        }
-
         gjs_debug(GJS_DEBUG_IMPORTER,
                   "JS import '%s' not found in %s",
                   name, dirname);
@@ -700,7 +677,6 @@ do_import(JSContext  *context,
 
     g_free(full_path);
     g_free(filename);
-    g_free(native_filename);
     g_free(dirname);
 
     if (!result &&
diff --git a/gjs/native.c b/gjs/native.c
index 168718b..e8a3c6b 100644
--- a/gjs/native.c
+++ b/gjs/native.c
@@ -183,36 +183,17 @@ gjs_is_registered_native_module(JSContext  *context,
  * gjs_import_native_module:
  * @context:
  * @module_obj:
- * @filename: filename or %NULL
  *
- * Imports a native module by g_module_open a shared library.
- * If @filename is %NULL, do not dlopen, assume the library
- * is already loaded in the modules hash table
+ * Return a native module that's been preloaded.
  */
 JSBool
-gjs_import_native_module(JSContext        *context,
-                         JSObject         *module_obj,
-                         const char       *filename)
+gjs_import_native_module(JSContext *context,
+                         JSObject  *module_obj)
 {
-    GModule *gmodule = NULL;
     GjsNativeModule *native_module;
     JSObject *parent;
     jsval tmp;
 
-    if (filename != NULL) {
-        /* Vital to load in global scope so any dependent libs
-         * are loaded into the main app. We don't want a second
-         * private copy of GTK or something.
-         */
-        gmodule = g_module_open(filename, 0);
-        if (gmodule == NULL) {
-            gjs_throw(context,
-                      "Failed to load '%s': %s",
-                      filename, g_module_error());
-            return JS_FALSE;
-        }
-    }
-
     /* dlopen() as a side effect should have registered us as
      * a native module. We just have to reverse-engineer
      * the module id from module_obj.
@@ -226,19 +207,8 @@ gjs_import_native_module(JSContext        *context,
         g_free(module_name);
     }
 
-    if (!native_module) {
-        if (gmodule)
-            g_module_close(gmodule);
+    if (!native_module)
         return JS_FALSE;
-    }
-
-    if (gmodule) {
-        /* make the module resident, which makes the close() a no-op
-         * (basically we leak the module permanently)
-         */
-        g_module_make_resident(gmodule);
-        g_module_close(gmodule);
-    }
 
     if (native_module->flags & GJS_NATIVE_SUPPLIES_MODULE_OBJ) {
 
diff --git a/gjs/native.h b/gjs/native.h
index 0dfde5d..27e5632 100644
--- a/gjs/native.h
+++ b/gjs/native.h
@@ -95,13 +95,9 @@ gboolean gjs_is_registered_native_module(JSContext  *context,
                                          JSObject   *parent,
                                          const char *name);
 
-/* called by importer.c to load a native module once it finds
- * it in the search path
- */
-JSBool gjs_import_native_module   (JSContext             *context,
-                                   JSObject              *module_obj,
-                                   const char            *filename);
-
+/* called by importer.c to load a statically linked native module */
+JSBool gjs_import_native_module (JSContext *context,
+                                 JSObject  *module_obj);
 
 G_END_DECLS
 


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