Re: Autoconfiscation patch for GTK+ on Win32



Sorry to respond to this only after you gave up and actually committed
the changes. :-(

Tor Lillqvist <tml iki fi> writes:

> /*
>  * 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 a
>  * 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;							   \

This is fine for me.

> /*
>  * Expands to a function called _get_##suffix that on non-Windows
>  * returns hardcoded_value. On Windows, deduce a pathname from the
>  * package, module_name and subdir, as described for
>  * g_win32_get_package_installation_subdirectory(). 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.
>  *
>  * Elsewhere in your code, wherever you would be tempted to write the
>  * name of a compile-time path macro, like FOOBAR_LIBDIR, instead use
>  * _get_libdir(), for instance.
>  */
> 
> #ifndef G_PLATFORM_WIN32
> # define G_HARDCODED_PATH_WRAPPER(hardcoded_value, package, suffix, module_name, subdir) \
> const gchar *			\
> _get_##suffix (void)		\
> {				\
>   return hardcoded_value;	\
> }
> #else
> # define G_HARDCODED_PATH_WRAPPER(hardcoded_value, package, suffix, module_name, subdir) \
> const gchar *								\
> _get_##suffix (void)							\
> {									\
>   static char *cached_##suffix = NULL;					\
>   if (cached_##suffix == NULL)						\
>     cached_##suffix = g_win32_get_package_installation_subdirectory	\
>       (package, module_name, subdir);					\
> 									\
>   return cached_##suffix;						\
> }
> #endif /* G_PLATFORM_WIN32 */

I don't like this much at _all_. It's a lot of magic for a little result.
 
 In gtkmain.c, one would then have:
> 
> G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
> 
> G_HARDCODED_PATH_WRAPPER (GTK_LIBDIR, GETTEXT_PACKAGE, libdir, dll_name, "lib")
> G_HARDCODED_PATH_WRAPPER (GTK_LOCALEDIR, GETTEXT_PACKAGE, localedir, dll_name, "lib/locale")
> G_HARDCODED_PATH_WRAPPER (GTK_SYSCONFDIR, GETTEXT_PACKAGE, sysconfdir, dll_name, "etc")
> G_HARDCODED_PATH_WRAPPER (GTK_DATA_PREFIX, GETTEXT_PACKAGE, data_prefix, dll_name, "")

[ BTW, Using GETTEXT_PACKAGE for this is abuse. If we think it's more general 
  than GETTEXT, it needs to be renamed. ]

> and code like
> 
>     default_dir = g_build_filename (_get_libdir (), "gtk-2.0", "modules", NULL);
> 
> Is this any cleaner? I am not sure myself...

I think writing it out is a lot easier to understand. Sorry to make you do
the work multiple times, but I'd prefer not to have G_HARDCODED_PATH_WRAPPER.

                                                         Owen




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]