From 6dbdc173a25c1e28b1111ab51d93c482bd184f1b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 13 May 2017 11:11:32 +0100 Subject: [PATCH] better prefix guessing on Windows see https://github.com/tumagonx/pygi-mingw-patches/issues/5 --- ChangeLog | 1 + libvips/include/vips/util.h | 2 +- libvips/iofuncs/init.c | 36 +++++++++++++----------------------- libvips/iofuncs/util.c | 14 +++++++------- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 91127f28..fbbfe86f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ - vips_conv(), vips_compass(), vips_convsep() default to FLOAT precision - add FORCE resize mode to break aspect ratio - add vips_thumbnail_image() +- better prefix guessing on Windows, thanks tumagonx 23/4/17 started 8.5.5 - doc polishing diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index fb26e5b6..413be3bf 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -332,7 +332,7 @@ guint32 vips__random( guint32 seed ); guint32 vips__random_add( guint32 seed, int value ); const char *vips__icc_dir( void ); -const char *vips__locale_dir( void ); +const char *vips__windows_prefix( void ); #ifdef __cplusplus } diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index 56a0c9c7..13a25611 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -267,6 +267,7 @@ vips_init( const char *argv0 ) char *prgname; const char *prefix; const char *libdir; + char *locale; /* Two stage done handling: 'done' means we've completed, 'started' * means we're currently initialising. Use this to prevent recursive @@ -341,7 +342,9 @@ vips_init( const char *argv0 ) /* Get i18n .mo files from $VIPSHOME/share/locale/. */ - bindtextdomain( GETTEXT_PACKAGE, vips__locale_dir() ); + locale = g_build_filename( prefix, "share", "locale", NULL ); + bindtextdomain( GETTEXT_PACKAGE, locale ); + g_free( locale ); bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" ); /* Deprecated, this is just for compat. @@ -953,8 +956,6 @@ const char * vips_guess_prefix( const char *argv0, const char *env_name ) { const char *prefix; - char *basename; - char name[VIPS_PATH_MAX]; /* Already set? */ @@ -966,29 +967,18 @@ vips_guess_prefix( const char *argv0, const char *env_name ) return( prefix ); } - /* Get the program name from argv0. - */ +#ifdef OS_WIN32 + prefix = vips__windows_prefix(); +#else +{ + char *basename; + basename = g_path_get_basename( argv0 ); - - /* Add the exe suffix, if it's missing. - */ - if( strlen( VIPS_EXEEXT ) > 0 ) { - const char *olds[] = { VIPS_EXEEXT }; - - vips__change_suffix( basename, name, - VIPS_PATH_MAX, VIPS_EXEEXT, olds, 1 ); - } - else - vips_strncpy( name, basename, VIPS_PATH_MAX ); - + prefix = guess_prefix( argv0, basename ); g_free( basename ); +} +#endif -#ifdef DEBUG - printf( "vips_guess_prefix: argv0 = %s\n", argv0 ); - printf( "vips_guess_prefix: name = %s\n", name ); -#endif /*DEBUG*/ - - prefix = guess_prefix( argv0, name ); g_setenv( env_name, prefix, TRUE ); return( prefix ); diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index ff33f248..769348d0 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1970,13 +1970,13 @@ vips__icc_dir( void ) } #ifdef OS_WIN32 -static HMODULE vips_dll = NULL; +static HMODULE vips__dll = NULL; #ifdef DLL_EXPORT BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { if( fdwReason == DLL_PROCESS_ATTACH ) - vips_dll = hinstDLL; + vips__dll = hinstDLL; return( TRUE ); } @@ -1984,25 +1984,25 @@ DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) #endif static void * -vips_locale_dir_once( void *null ) +vips__windows_prefix_once( void *null ) { char *prefix; #ifdef OS_WIN32 prefix = g_win32_get_package_installation_directory_of_module( - vips_dll ), + vips__dll ), #else prefix = (char *) g_getenv( "VIPSHOME" ); #endif - return( (void *) g_build_filename( prefix, "share", "locale", NULL ) ); + return( (void *) prefix ); } const char * -vips__locale_dir( void ) +vips__windows_prefix( void ) { static GOnce once = G_ONCE_INIT; return( (const char *) g_once( &once, - (GThreadFunc) vips_locale_dir_once, NULL ) ); + (GThreadFunc) vips__windows_prefix_once, NULL ) ); }