From: Tor Lillqvist Date: Mon, 22 Oct 2001 23:19:19 +0000 (+0000) Subject: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and G_HARDCODED_PATH_WRAPPER. X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=3984621bd31851ff73192c22cfc54f2bd7ecd511;p=dana%2Fcg-glib.git Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and G_HARDCODED_PATH_WRAPPER. 2001-10-23 Tor Lillqvist * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path names into Windows DLLs. * glib/gutils.c: Use them for GLIB_LOCALEDIR. * glib/gwin32.c (get_package_directory_from_module): Plug a small memory leak. Minor code reordering. (g_win32_get_package_installation_subdirectory): Allow empty subdir. --- diff --git a/ChangeLog b/ChangeLog index f32944d9..59ac36c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,16 @@ library, install it. Install the gcc import library. Also support uninstall. + * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and + G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path + names into Windows DLLs. + + * glib/gutils.c: Use them for GLIB_LOCALEDIR. + + * glib/gwin32.c (get_package_directory_from_module): Plug a small + memory leak. Minor code reordering. + (g_win32_get_package_installation_subdirectory): Allow empty subdir. + 2001-10-19 Tor Lillqvist * configure.in: Fix test for lib.exe. Can't set ms_librarian diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index f32944d9..59ac36c6 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -9,6 +9,16 @@ library, install it. Install the gcc import library. Also support uninstall. + * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and + G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path + names into Windows DLLs. + + * glib/gutils.c: Use them for GLIB_LOCALEDIR. + + * glib/gwin32.c (get_package_directory_from_module): Plug a small + memory leak. Minor code reordering. + (g_win32_get_package_installation_subdirectory): Allow empty subdir. + 2001-10-19 Tor Lillqvist * configure.in: Fix test for lib.exe. Can't set ms_librarian diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index f32944d9..59ac36c6 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -9,6 +9,16 @@ library, install it. Install the gcc import library. Also support uninstall. + * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and + G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path + names into Windows DLLs. + + * glib/gutils.c: Use them for GLIB_LOCALEDIR. + + * glib/gwin32.c (get_package_directory_from_module): Plug a small + memory leak. Minor code reordering. + (g_win32_get_package_installation_subdirectory): Allow empty subdir. + 2001-10-19 Tor Lillqvist * configure.in: Fix test for lib.exe. Can't set ms_librarian diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index f32944d9..59ac36c6 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -9,6 +9,16 @@ library, install it. Install the gcc import library. Also support uninstall. + * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and + G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path + names into Windows DLLs. + + * glib/gutils.c: Use them for GLIB_LOCALEDIR. + + * glib/gwin32.c (get_package_directory_from_module): Plug a small + memory leak. Minor code reordering. + (g_win32_get_package_installation_subdirectory): Allow empty subdir. + 2001-10-19 Tor Lillqvist * configure.in: Fix test for lib.exe. Can't set ms_librarian diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index f32944d9..59ac36c6 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -9,6 +9,16 @@ library, install it. Install the gcc import library. Also support uninstall. + * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and + G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path + names into Windows DLLs. + + * glib/gutils.c: Use them for GLIB_LOCALEDIR. + + * glib/gwin32.c (get_package_directory_from_module): Plug a small + memory leak. Minor code reordering. + (g_win32_get_package_installation_subdirectory): Allow empty subdir. + 2001-10-19 Tor Lillqvist * configure.in: Fix test for lib.exe. Can't set ms_librarian diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index f32944d9..59ac36c6 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -9,6 +9,16 @@ library, install it. Install the gcc import library. Also support uninstall. + * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and + G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path + names into Windows DLLs. + + * glib/gutils.c: Use them for GLIB_LOCALEDIR. + + * glib/gwin32.c (get_package_directory_from_module): Plug a small + memory leak. Minor code reordering. + (g_win32_get_package_installation_subdirectory): Allow empty subdir. + 2001-10-19 Tor Lillqvist * configure.in: Fix test for lib.exe. Can't set ms_librarian diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index f32944d9..59ac36c6 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -9,6 +9,16 @@ library, install it. Install the gcc import library. Also support uninstall. + * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and + G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path + names into Windows DLLs. + + * glib/gutils.c: Use them for GLIB_LOCALEDIR. + + * glib/gwin32.c (get_package_directory_from_module): Plug a small + memory leak. Minor code reordering. + (g_win32_get_package_installation_subdirectory): Allow empty subdir. + 2001-10-19 Tor Lillqvist * configure.in: Fix test for lib.exe. Can't set ms_librarian diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index f32944d9..59ac36c6 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -9,6 +9,16 @@ library, install it. Install the gcc import library. Also support uninstall. + * glib/gutils.h: Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and + G_HARDCODED_PATH_WRAPPER. These are used to avoid hardcoding path + names into Windows DLLs. + + * glib/gutils.c: Use them for GLIB_LOCALEDIR. + + * glib/gwin32.c (get_package_directory_from_module): Plug a small + memory leak. Minor code reordering. + (g_win32_get_package_installation_subdirectory): Allow empty subdir. + 2001-10-19 Tor Lillqvist * configure.in: Fix test for lib.exe. Can't set ms_librarian diff --git a/glib/gutils.c b/glib/gutils.c index 26995445..7fb0007e 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1093,43 +1093,8 @@ g_get_codeset (void) #include - -#ifdef G_OS_WIN32 - -/* DllMain function needed to tuck away the GLib DLL name */ - -static char dll_name[MAX_PATH]; - -BOOL WINAPI -DllMain (HINSTANCE hinstDLL, - DWORD fdwReason, - LPVOID lpvReserved) -{ - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - GetModuleFileName ((HMODULE) hinstDLL, dll_name, sizeof (dll_name)); - break; - } - - return TRUE; -} - -/* On Windows we don't want any hard-coded path names */ - -#undef GLIB_LOCALE_DIR -/* It's OK to leak the g_win32_get_...() and g_path_get_basename() results - * below, as this macro is called only once. - * Use the actual DLL name of the GLib DLL, i.e. don't assume the - * GLib DLL has a certain name. - */ -#define GLIB_LOCALE_DIR \ - g_win32_get_package_installation_subdirectory \ - (GETTEXT_PACKAGE, \ - g_path_get_basename (dll_name), \ - "share\\locale") - -#endif /* !G_OS_WIN32 */ +G_WIN32_DLLMAIN_FOR_DLL_NAME (static, dll_name) +G_HARDCODED_PATH_WRAPPER (GLIB_LOCALE_DIR, GETTEXT_PACKAGE, _glib_get_locale_dir, dll_name, "lib/locale") G_CONST_RETURN gchar * _glib_gettext (const gchar *str) @@ -1138,7 +1103,7 @@ _glib_gettext (const gchar *str) if (!_glib_gettext_initialized) { - bindtextdomain(GETTEXT_PACKAGE, GLIB_LOCALE_DIR); + bindtextdomain(GETTEXT_PACKAGE, _glib_get_locale_dir ()); _glib_gettext_initialized = TRUE; } diff --git a/glib/gutils.h b/glib/gutils.h index f4494838..e8dce6f3 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -330,7 +330,82 @@ GLIB_VAR const guint glib_binary_age; G_END_DECLS -#endif /* __G_UTILS_H__ */ +/* + * On Windows, this macro defines a DllMain function that stores the + * actual DLL name that the code being compiled will be included in. + * STATIC should be empty or 'static'. DLL_NAME is the name of the + * (pointer to the) char array where the DLL name will be stored. If + * this is used, you must also include . If you need a more complex + * DLL entry point function, you cannot use this. + * + * On non-Windows platforms, expands to nothing. + */ +#ifndef G_PLATFORM_WIN32 +# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) +#else +# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \ +static char *dll_name; \ + \ +BOOL WINAPI \ +DllMain (HINSTANCE hinstDLL, \ + DWORD fdwReason, \ + LPVOID lpvReserved) \ +{ \ + char bfr[1000]; \ + switch (fdwReason) \ + { \ + case DLL_PROCESS_ATTACH: \ + GetModuleFileName ((HMODULE) hinstDLL, bfr, sizeof (bfr)); \ + dll_name = g_path_get_basename (bfr); \ + break; \ + } \ + \ + return TRUE; \ +} +#endif /* G_PLATFORM_WIN32 */ +/* + * Expands to a function called FUNCTION that on non-Windows + * returns HARDCODED_VALUE. On Windows, deduce a pathname from + * the MODULE_NAME, PACKAGE and SUBDIR. If the code being compiled + * goes into a DLL, MODULE_NAME should be the dll_name passed to + * G_WIN32_DLLMAIN_FOR_DLL_NAME. If the code is for a .EXE, use NULL. + * + * An example: Wherever you would be tempted to write the name of a + * compile-time path macro, like FOOBAR_LIBDIR, instead use + * _get_foobar_libdir(). This requires you to insert in one place in + * your code something like this: + +G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) +G_HARDCODED_PATH_WRAPPER(FOOBAR_LIBDIR, GETTEXT_PACKAGE, _get_foobar_libdir, dll_name, "lib") + + * This will on Windows define the DllMain function, and always define + * the _get_foobar_libdir() function. On Windows, this function + * calculates the value corresponding to FOOBAR_LIBDIR at run-time, on + * other systems it returns said constant, as configured before + * compilation. + */ +#ifndef G_PLATFORM_WIN32 +# define G_HARDCODED_PATH_WRAPPER(hardcoded_value, package, function, module_name, subdir) \ +const gchar * \ +function (void) \ +{ \ + return hardcoded_value; \ +} +#else +# define G_HARDCODED_PATH_WRAPPER(hardcoded_value, package, function, module_name, subdir) \ +const gchar * \ +function (void) \ +{ \ + static char *cache = NULL; \ + if (cache == NULL) \ + cache = g_win32_get_package_installation_subdirectory \ + (package, module_name, subdir); \ + \ + return cache; \ +} +#endif + +#endif /* __G_UTILS_H__ */ diff --git a/glib/gwin32.c b/glib/gwin32.c index 5d22bf71..6c8c3f0c 100644 --- a/glib/gwin32.c +++ b/glib/gwin32.c @@ -611,9 +611,18 @@ get_package_directory_from_module (gchar *module_name) if (!GetModuleFileName (hmodule, fn, MAX_PATH)) { G_UNLOCK (module_dirs); + g_free (fn); return NULL; } + if ((p = strrchr (fn, G_DIR_SEPARATOR)) != NULL) + *p = '\0'; + + p = strrchr (fn, G_DIR_SEPARATOR); + if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0 || + g_ascii_strcasecmp (p + 1, "lib") == 0)) + *p = '\0'; + #ifdef G_WITH_CYGWIN /* In Cygwin we need to have POSIX paths */ { @@ -625,14 +634,6 @@ get_package_directory_from_module (gchar *module_name) } #endif - if ((p = strrchr (fn, G_DIR_SEPARATOR)) != NULL) - *p = '\0'; - - p = strrchr (fn, G_DIR_SEPARATOR); - if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0 || - g_ascii_strcasecmp (p + 1, "lib") == 0)) - *p = '\0'; - g_hash_table_insert (module_dirs, module_name ? module_name : "", fn); G_UNLOCK (module_dirs); @@ -770,7 +771,7 @@ g_win32_get_package_installation_subdirectory (gchar *package, prefix = g_win32_get_package_installation_directory (package, dll_name); - sep = (prefix[strlen (prefix) - 1] == G_DIR_SEPARATOR ? + sep = ((subdir != NULL && strlen (subdir) > 0) || prefix[strlen (prefix) - 1] == G_DIR_SEPARATOR ? "" : G_DIR_SEPARATOR_S); return g_strconcat (prefix, sep, subdir, NULL);