ORBit2 r2092 - in trunk: . src/orb/orb-core src/orb/util
- From: tml svn gnome org
- To: svn-commits-list gnome org
- Subject: ORBit2 r2092 - in trunk: . src/orb/orb-core src/orb/util
- Date: Thu, 25 Sep 2008 23:05:51 +0000 (UTC)
Author: tml
Date: Thu Sep 25 23:05:51 2008
New Revision: 2092
URL: http://svn.gnome.org/viewvc/ORBit2?rev=2092&view=rev
Log:
2008-09-26 Tor Lillqvist <tml novell com>
* src/orb/orb-core/corba-orb.c [Win32]: A DllMain() function
shouldn't really call functions in other DLLs. Just save the
HMODULE of the libORBit-2 DLL. Don't calculate the typelib
directory and system rcfile paths in DllMain(), do it as needed in
separate functions. Simplyfy code by using
g_win32_get_package_installation_directory_of_module().
* src/orb/orb-core/orb-core-private.h
* src/orb/util/orbit-options.c: Corresponding changes.
Modified:
trunk/ChangeLog
trunk/src/orb/orb-core/corba-orb.c
trunk/src/orb/orb-core/orb-core-private.h
trunk/src/orb/util/orbit-options.c
Modified: trunk/src/orb/orb-core/corba-orb.c
==============================================================================
--- trunk/src/orb/orb-core/corba-orb.c (original)
+++ trunk/src/orb/orb-core/corba-orb.c Thu Sep 25 23:05:51 2008
@@ -23,13 +23,6 @@
OrbitDebugFlags _orbit_debug_flags = ORBIT_DEBUG_NONE;
#endif
-#ifdef G_OS_WIN32
-/* Silence gcc warning about no prototype */
-BOOL WINAPI DllMain (HINSTANCE hinstDLL,
- DWORD fdwReason,
- LPVOID lpvReserved);
-#endif
-
/*
* Command line option handling.
*/
@@ -1481,66 +1474,75 @@
#ifdef G_OS_WIN32
-const gchar *ORBit_win32_typelib_dir;
-const gchar *ORBit_win32_system_rcfile;
+/* DllMain function used to store the DLL handle */
+static HMODULE hmodule;
+G_LOCK_DEFINE_STATIC (mutex);
+
+/* Silence gcc warnings about no prototype */
+BOOL WINAPI DllMain (HINSTANCE hinstDLL,
+ DWORD fdwReason,
+ LPVOID lpvReserved);
+const gchar *ORBit_win32_get_typelib_dir (void);
+const gchar *ORBit_win32_get_system_rcfile (void);
-/* DllMain function needed to fetch the DLL name and deduce the
- * installation directory from that, and then form the pathnames for
- * the typelib directory and system orbitrc file.
- */
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
- wchar_t wcbfr[1000];
- char cpbfr[1000];
- char *dll_name = NULL;
- gchar *prefix;
-
- switch (fdwReason) {
- case DLL_PROCESS_ATTACH:
- /* GLib 2.6 uses UTF-8 file names */
- if (GetVersion () < 0x80000000) {
- /* NT-based Windows has wide char API */
- if (GetModuleFileNameW ((HMODULE) hinstDLL,
- wcbfr, G_N_ELEMENTS (wcbfr)))
- dll_name = g_utf16_to_utf8 (wcbfr, -1,
- NULL, NULL, NULL);
- } else {
- /* Win9x, yecch */
- if (GetModuleFileNameA ((HMODULE) hinstDLL,
- cpbfr, G_N_ELEMENTS (cpbfr)))
- dll_name = g_locale_to_utf8 (cpbfr, -1,
- NULL, NULL, NULL);
- }
-
- if (dll_name) {
- gchar *p = strrchr (dll_name, '\\');
-
- if (p != NULL)
- *p = '\0';
-
- p = strrchr (dll_name, '\\');
- if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0))
- *p = '\0';
-
- prefix = dll_name;
- } else {
- prefix = g_strdup ("");
- }
-
- ORBit_win32_typelib_dir = g_strconcat (prefix,
- "\\lib\\orbit-2.0",
- NULL);
- ORBit_win32_system_rcfile = g_strconcat (prefix,
- "\\etc\\orbitrc",
- NULL);
- g_free (prefix);
- break;
- }
+ switch (fdwReason) {
+ case DLL_PROCESS_ATTACH:
+ hmodule = hinstDLL;
+ break;
+ }
+ return TRUE;
+}
- return TRUE;
+static const char *typelib_dir = NULL;
+static const char *system_rcfile = NULL;
+
+static void
+setup (void)
+{
+ gchar *prefix;
+
+ G_LOCK (mutex);
+ if (typelib_dir != NULL) {
+ G_UNLOCK (mutex);
+ return;
+ }
+
+ prefix = g_win32_get_package_installation_directory_of_module (hmodule);
+
+ if (prefix == NULL) {
+ /* Just to not crash... */
+ prefix = g_strdup ("");
+ }
+
+ typelib_dir = g_strconcat (prefix,
+ "\\lib\\orbit-2.0",
+ NULL);
+
+ system_rcfile = g_strconcat (prefix,
+ "\\etc\\orbitrc",
+ NULL);
+ G_UNLOCK (mutex);
+
+ g_free (prefix);
+}
+
+const gchar *
+ORBit_win32_get_typelib_dir (void)
+{
+ setup ();
+ return typelib_dir;
+}
+
+const gchar *
+ORBit_win32_get_system_rcfile (void)
+{
+ setup ();
+ return system_rcfile;
}
#endif
Modified: trunk/src/orb/orb-core/orb-core-private.h
==============================================================================
--- trunk/src/orb/orb-core/orb-core-private.h (original)
+++ trunk/src/orb/orb-core/orb-core-private.h Thu Sep 25 23:05:51 2008
@@ -78,9 +78,9 @@
#ifdef G_OS_WIN32
-extern const gchar *ORBit_win32_typelib_dir;
+extern const gchar *ORBit_win32_get_typelib_dir (void);
#undef ORBIT_TYPELIB_DIR
-#define ORBIT_TYPELIB_DIR ORBit_win32_typelib_dir
+#define ORBIT_TYPELIB_DIR ORBit_win32_get_typelib_dir ()
#endif
#endif
Modified: trunk/src/orb/util/orbit-options.c
==============================================================================
--- trunk/src/orb/util/orbit-options.c (original)
+++ trunk/src/orb/util/orbit-options.c Thu Sep 25 23:05:51 2008
@@ -9,10 +9,10 @@
#include "orbit-options.h"
#ifdef G_OS_WIN32
-extern const gchar *ORBit_win32_system_rcfile;
+extern const gchar *ORBit_win32_get_system_rcfile (void);
#undef ORBIT_SYSTEM_RCFILE
-#define ORBIT_SYSTEM_RCFILE ORBit_win32_system_rcfile
+#define ORBIT_SYSTEM_RCFILE ORBit_win32_get_system_rcfile ()
#endif
#undef DEBUG
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]