]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
Use GetErrorMode if it is available.
authorPeter Rosin <peda@lysator.liu.se>
Mon, 18 Jan 2010 08:48:23 +0000 (09:48 +0100)
committerPeter Rosin <peda@lysator.liu.se>
Mon, 18 Jan 2010 08:48:23 +0000 (09:48 +0100)
* libltdl/loaders/loadlibrary.c (wrap_geterrormode): New
function that checks if GetErrorMode is supported by the
system and makes use of it if it is.
(fallback_geterrormode): New function that is used otherwise
that implements the old workaround.
(geterrormode): New function pointer that points at either
of the above or directly at GetErrorMode.
(vm_open): Make use of the above.

Signed-off-by: Peter Rosin <peda@lysator.liu.se>
ChangeLog
libltdl/loaders/loadlibrary.c

index b244706b2ed4c4777df400fa6b1c2e432a1fd1f2..5f2518ca44787409c212e2d90827c34a9cc3b32c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-01-02  Peter Rosin  <peda@lysator.liu.se>
+
+       Use GetErrorMode if it is available.
+       * libltdl/loaders/loadlibrary.c (wrap_geterrormode): New
+       function that checks if GetErrorMode is supported by the
+       system and makes use of it if it is.
+       (fallback_geterrormode): New function that is used otherwise
+       that implements the old workaround.
+       (geterrormode): New function pointer that points at either
+       of the above or directly at GetErrorMode.
+       (vm_open): Make use of the above.
+
 2010-01-11  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        Ensure functions from resident modules work in atexit handlers.
index 97fddf46108f4066528ddb5024dc3aae05728e0b..40435fe4b20e8ff9372844031a817a3ad28c52e7 100644 (file)
@@ -1,7 +1,7 @@
 /* loader-loadlibrary.c --  dynamic linking for Win32
 
    Copyright (C) 1998, 1999, 2000, 2004, 2005, 2006,
-                 2007, 2008 Free Software Foundation, Inc.
+                 2007, 2008, 2010 Free Software Foundation, Inc.
    Written by Thomas Tanner, 1998
 
    NOTE: The canonical source of this file is maintained with the
@@ -98,6 +98,14 @@ get_vtable (lt_user_data loader_data)
 
 #include <windows.h>
 
+static UINT WINAPI wrap_geterrormode (void);
+static UINT WINAPI fallback_geterrormode (void);
+
+typedef UINT (WINAPI geterrormode_type) (void);
+
+static geterrormode_type *geterrormode = wrap_geterrormode;
+
+
 /* A function called through the vtable when this loader is no
    longer needed by the application.  */
 static int
@@ -170,16 +178,14 @@ vm_open (lt_user_data LT__UNUSED loader_data, const char *filename,
     }
 
   {
-    /* Silence dialog from LoadLibrary on some failures.
-       No way to get the error mode, but to set it,
-       so set it twice to preserve any previous flags. */
-    UINT errormode = SetErrorMode(SEM_FAILCRITICALERRORS);
-    SetErrorMode(errormode | SEM_FAILCRITICALERRORS);
+    /* Silence dialog from LoadLibrary on some failures. */
+    UINT errormode = geterrormode ();
+    SetErrorMode (errormode | SEM_FAILCRITICALERRORS);
 
     module = LoadLibrary (wpath);
 
     /* Restore the error mode. */
-    SetErrorMode(errormode);
+    SetErrorMode (errormode);
   }
 
   /* libltdl expects this function to fail if it is unable
@@ -249,3 +255,34 @@ vm_sym (lt_user_data LT__UNUSED loader_data, lt_module module, const char *name)
 
   return address;
 }
+
+
+
+/* --- HELPER FUNCTIONS --- */
+
+
+/* A function called through the geterrormode variable which checks
+   if the system supports GetErrorMode and arranges for it or a
+   fallback implementation to be called directly in the future. The
+   selected version is then called. */
+static UINT WINAPI
+wrap_geterrormode (void)
+{
+  HMODULE kernel32 = GetModuleHandleA ("kernel32.dll");
+  geterrormode = (geterrormode_type *) GetProcAddress (kernel32,
+                                                       "GetErrorMode");
+  if (!geterrormode)
+    geterrormode = fallback_geterrormode;
+  return geterrormode ();
+}
+
+/* A function called through the geterrormode variable for cases
+   where the system does not support GetErrorMode */
+static UINT WINAPI
+fallback_geterrormode (void)
+{
+  /* Prior to Windows Vista, the only way to get the current error
+     mode was to set a new one. In our case, we are setting a new
+     error mode right after "getting" it, so that's fairly ok. */
+  return SetErrorMode (SEM_FAILCRITICALERRORS);
+}