If a symbol is not in metadata->module, look for it in the global module,
authorHavoc Pennington <hp@pobox.com>
Wed, 23 Apr 2008 01:24:57 +0000 (01:24 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Wed, 23 Apr 2008 01:24:57 +0000 (01:24 +0000)
2008-04-22  Havoc Pennington  <hp@pobox.com>

* girepository/ginvoke.c (g_function_info_invoke): If a symbol is
not in metadata->module, look for it in the global module, in case
some other object or the app itself provides the symbol.

svn path=/trunk/; revision=221

ChangeLog
girepository/ginvoke.c

index 1604b90..04c2ea9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-04-22  Havoc Pennington  <hp@pobox.com>
 
+       * girepository/ginvoke.c (g_function_info_invoke): If a symbol is
+       not in metadata->module, look for it in the global module, in case
+       some other object or the app itself provides the symbol.
+
+2008-04-22  Havoc Pennington  <hp@pobox.com>
+
        * girepository/gmetadata.c (_g_metadata_init): hack to avoid
        dlopening a library that is already in the main app, by checking
        whether one of the lib's symbols is already loaded.
index 986ca78..26f3c58 100644 (file)
@@ -166,12 +166,36 @@ g_function_info_invoke (GIFunctionInfo *info,
   if (!g_module_symbol (g_base_info_get_metadata((GIBaseInfo *) info)->module,
                         symbol, &func))
     {
-      g_set_error (error,
-                  G_INVOKE_ERROR,
-                  G_INVOKE_ERROR_SYMBOL_NOT_FOUND,
-                  "Could not locate %s: %s", symbol, g_module_error ());
-                  
-      return FALSE;
+      GModule *entire_app;
+
+      /*
+       * We want to be able to add symbols to an app or an auxiliary
+       * library to fill in gaps in an introspected library. However,
+       * normally we would only look for symbols in the main library
+       * (metadata->module).
+       *
+       * A more elaborate solution is probably possible, but as a
+       * simple approach for now, if we fail to find a symbol we look
+       * for it in the global module.
+       *
+       * This would not be very efficient if it happened often, since
+       * we always do the failed lookup above first, but very few
+       * symbols should be outside of metadata->module so it doesn't
+       * matter.
+       */
+      entire_app = g_module_open (NULL, 0);
+      if (!g_module_symbol (entire_app, symbol, &func))
+        {
+          g_set_error (error,
+                       G_INVOKE_ERROR,
+                       G_INVOKE_ERROR_SYMBOL_NOT_FOUND,
+                       "Could not locate %s: %s", symbol, g_module_error ());
+          
+          g_module_close (entire_app);
+          
+          return FALSE;
+        }
+      g_module_close (entire_app);
     }
 
   tinfo = g_callable_info_get_return_type ((GICallableInfo *)info);