Add macros G_WIN32_DLLMAIN_FOR_DLL_NAME and G_HARDCODED_PATH_WRAPPER.

2001-10-23  Tor Lillqvist  <tml@iki.fi>

	* 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.
This commit is contained in:
Tor Lillqvist 2001-10-22 23:19:19 +00:00 committed by Tor Lillqvist
parent a0b08581c0
commit 3984621bd3
11 changed files with 171 additions and 50 deletions

View File

@ -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 <tml@iki.fi>
* configure.in: Fix test for lib.exe. Can't set ms_librarian

View File

@ -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 <tml@iki.fi>
* configure.in: Fix test for lib.exe. Can't set ms_librarian

View File

@ -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 <tml@iki.fi>
* configure.in: Fix test for lib.exe. Can't set ms_librarian

View File

@ -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 <tml@iki.fi>
* configure.in: Fix test for lib.exe. Can't set ms_librarian

View File

@ -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 <tml@iki.fi>
* configure.in: Fix test for lib.exe. Can't set ms_librarian

View File

@ -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 <tml@iki.fi>
* configure.in: Fix test for lib.exe. Can't set ms_librarian

View File

@ -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 <tml@iki.fi>
* configure.in: Fix test for lib.exe. Can't set ms_librarian

View File

@ -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 <tml@iki.fi>
* configure.in: Fix test for lib.exe. Can't set ms_librarian

View File

@ -1093,43 +1093,8 @@ g_get_codeset (void)
#include <libintl.h>
#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;
}

View File

@ -330,7 +330,82 @@ GLIB_VAR const guint glib_binary_age;
G_END_DECLS
/*
* 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 <windows.h>. 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__ */

View File

@ -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);