2.19.0
[platform/upstream/glib.git] / gmodule / gmodule.c
index 0ff4eaa..1ebb63e 100644 (file)
  * MT safe
  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include       "gstdio.h"
-#include       "gmodule.h"
-#include       "gmoduleconf.h"
-#include       <errno.h>
-#include       <string.h>
-#include       <sys/types.h>
-#include       <sys/stat.h>
-#include       <fcntl.h>
+#include "config.h"
+
+#include "glib.h"
+
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #ifdef HAVE_UNISTD_H
-# include <unistd.h>
+#include <unistd.h>
 #endif
-#if defined (G_OS_WIN32)
-# include <io.h>               /* For open() and close() prototypes. */
+#ifdef G_OS_WIN32
+#include <io.h>                /* For open() and close() prototypes. */
 #endif
 
+#include "gmoduleconf.h"
+#include "gstdio.h"
+#include "gmodule.h"
+
 /* We maintain a list of modules, so we can reference count them.
  * That's needed because some platforms don't support refernce counts on
  * modules e.g. the shl_* implementation of HP-UX
@@ -59,7 +61,7 @@
 struct _GModule
 {
   gchar        *file_name;
-#ifdef G_OS_WIN32
+#if defined (G_OS_WIN32) && !defined(_WIN64)
   gchar *cp_file_name;
 #endif
   gpointer handle;
@@ -353,7 +355,7 @@ g_module_open (const gchar    *file_name,
            {
              main_module = g_new (GModule, 1);
              main_module->file_name = NULL;
-#ifdef G_OS_WIN32
+#if defined (G_OS_WIN32) && !defined(_WIN64)
              main_module->cp_file_name = NULL;
 #endif
              main_module->handle = handle;
@@ -427,8 +429,11 @@ g_module_open (const gchar    *file_name,
          gchar *real_name = parse_libtool_archive (name);
 
          /* real_name might be NULL, but then module error is already set */
-         g_free (name);
-         name = real_name;
+         if (real_name)
+           {
+             g_free (name);
+             name = real_name;
+            }
        }
       if (name)
        handle = _g_module_open (name, (flags & G_MODULE_BIND_LAZY) != 0,
@@ -465,7 +470,7 @@ g_module_open (const gchar    *file_name,
       
       module = g_new (GModule, 1);
       module->file_name = g_strdup (file_name);
-#ifdef G_OS_WIN32
+#if defined (G_OS_WIN32) && !defined(_WIN64)
       module->cp_file_name = g_locale_from_utf8 (file_name, -1,
                                                 NULL, NULL, NULL);
 #endif
@@ -477,7 +482,7 @@ g_module_open (const gchar    *file_name,
       modules = module;
       
       /* check initialization */
-      if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init))
+      if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init) && check_init != NULL)
        check_failed = check_init (module);
       
       /* we don't call unload() if the initialization check failed. */
@@ -488,7 +493,10 @@ g_module_open (const gchar    *file_name,
        {
          gchar *error;
 
-         error = g_strconcat ("GModule initialization check failed: ", check_failed, NULL);
+         error = g_strconcat ("GModule (", 
+                               file_name ? file_name : "NULL", 
+                               ") initialization check failed: ", 
+                               check_failed, NULL);
          g_module_close (module);
          module = NULL;
          g_module_set_error (error);
@@ -508,7 +516,7 @@ g_module_open (const gchar    *file_name,
   return module;
 }
 
-#ifdef G_OS_WIN32
+#if defined (G_OS_WIN32) && !defined(_WIN64)
 
 #undef g_module_open
 
@@ -572,7 +580,7 @@ g_module_close (GModule            *module)
       
       _g_module_close (module->handle, FALSE);
       g_free (module->file_name);
-#ifdef G_OS_WIN32
+#if defined (G_OS_WIN32) && !defined(_WIN64)
       g_free (module->cp_file_name);
 #endif
       g_free (module);
@@ -651,7 +659,7 @@ g_module_name (GModule *module)
   return module->file_name;
 }
 
-#ifdef G_OS_WIN32
+#if defined (G_OS_WIN32) && !defined(_WIN64)
 
 #undef g_module_name