gmodule: Two minor g-i annotations fixes
[platform/upstream/glib.git] / gmodule / gmodule-dld.c
index 552b8fa..401b32f 100644 (file)
@@ -1,21 +1,34 @@
 /* GMODULE - GLIB wrapper code for dynamic module loading
- * Copyright (C) 1998 Tim Janik
+ * Copyright (C) 1998, 2000 Tim Janik
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+
+/*
+ * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GLib Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+/* 
+ * MT safe
+ */
+#include "config.h"
+
 #include <dl.h>
 
 
 
 
 /* --- functions --- */
+
+/*
+ * shl_load() does not appear to support making symbols invisible to
+ * the global namespace.  However, the default is to put the library
+ * last in the search order, which is approximately what we want,
+ * since it will cause symbols that conflict with existing symbols to
+ * be invisible.  It is unclear if BIND_FIRST should be used when
+ * bind_local==0, since it may cause the loaded symbols to be used
+ * preferentially to the application's symbols, which is Almost
+ * Always Wrong.  --ds
+ */
 static gpointer
-_g_module_open (const gchar    *file_name,
-               gboolean        bind_lazy)
+_g_module_open (const gchar *file_name,
+               gboolean     bind_lazy,
+               gboolean     bind_local)
 {
   shl_t shl_handle;
   
@@ -85,8 +110,8 @@ _g_module_self (void)
 }
 
 static void
-_g_module_close (gpointer        handle,
-                gboolean         is_unref)
+_g_module_close (gpointer handle,
+                gboolean is_unref)
 {
   if (!is_unref)
     {
@@ -96,13 +121,22 @@ _g_module_close (gpointer    handle,
 }
 
 static gpointer
-_g_module_symbol (gpointer       handle,
-                 const gchar    *symbol_name)
+_g_module_symbol (gpointer     handle,
+                 const gchar *symbol_name)
 {
   gpointer p = NULL;
   
   /* should we restrict lookups to TYPE_PROCEDURE?
    */
+  if (handle == PROG_HANDLE)
+    {
+      /* PROG_HANDLE will only lookup symbols in the program itself, not honouring
+       * libraries. passing NULL as a handle will also try to lookup the symbol
+       * in currently loaded libraries. fix pointed out and supplied by:
+       * David Gero <dgero@nortelnetworks.com>
+       */
+      handle = NULL;
+    }
   if (shl_findsym ((shl_t*) &handle, symbol_name, TYPE_UNDEFINED, &p) != 0 ||
       handle == NULL || p == NULL)
     {
@@ -112,3 +146,18 @@ _g_module_symbol (gpointer   handle,
   
   return p;
 }
+
+static gchar*
+_g_module_build_path (const gchar *directory,
+                     const gchar *module_name)
+{
+  if (directory && *directory)
+    if (strncmp (module_name, "lib", 3) == 0)
+      return g_strconcat (directory, "/", module_name, NULL);
+    else
+      return g_strconcat (directory, "/lib", module_name, ".sl", NULL);
+  else if (strncmp (module_name, "lib", 3) == 0)
+    return g_strdup (module_name);
+  else
+    return g_strconcat ("lib", module_name, ".sl", NULL);
+}