From c5e675f7db4c8f5a8581724742579f4878d89b74 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 10 Jan 2017 14:12:24 +0000 Subject: [PATCH] fix --vips-cache-max etc. --vips-cache-max, --vips-cache-max-memory and --vips-cache-max-files were not working and probably hadn't been for a while vipsthumbnail.c turns off the operation cache, it's not useful for the same operation repeated across many files --- ChangeLog | 1 + libvips/include/vips/internal.h | 5 ----- libvips/iofuncs/cache.c | 15 --------------- libvips/iofuncs/init.c | 33 ++++++++++++++++++++++++++++++--- libvips/resample/thumbnail.c | 26 ++++++++++++++++++++++++++ tools/vipsthumbnail.c | 4 ++++ 6 files changed, 61 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index b00adb01..32a4f5c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ VIPS_LIBRARY_AGE - better support for bscale / bzero in fits images - deprecate vips_warn() / vips_info(); use g_warning() / g_info() instead +- fix --vips-cache-max etc. 8/12/16 started 8.4.5 - allow libgsf-1.14.26 to help centos, thanks tdiprima diff --git a/libvips/include/vips/internal.h b/libvips/include/vips/internal.h index 1fa940a1..379d0ad7 100644 --- a/libvips/include/vips/internal.h +++ b/libvips/include/vips/internal.h @@ -94,11 +94,6 @@ extern int vips__info; */ extern char *vips__disc_threshold; -/* Cache size settings. - */ -extern char *vips__cache_max; -extern char *vips__cache_max_mem; -extern char *vips__cache_max_files; extern gboolean vips__cache_dump; extern gboolean vips__cache_trace; diff --git a/libvips/iofuncs/cache.c b/libvips/iofuncs/cache.c index c2393e2e..d5810fc3 100644 --- a/libvips/iofuncs/cache.c +++ b/libvips/iofuncs/cache.c @@ -67,9 +67,6 @@ /* Set by GOption from the command line, eg. "12m". */ -char *vips__cache_max = NULL; -char *vips__cache_max_mem = NULL; -char *vips__cache_max_files = NULL; gboolean vips__cache_dump = FALSE; gboolean vips__cache_trace = FALSE; @@ -456,18 +453,6 @@ vips__cache_init( void ) vips_cache_table = g_hash_table_new( (GHashFunc) vips_operation_hash, (GEqualFunc) vips_operation_equal ); - - if( vips__cache_max ) - vips_cache_max = - vips__parse_size( vips__cache_max ); - - if( vips__cache_max_mem ) - vips_cache_max_mem = - vips__parse_size( vips__cache_max_mem ); - - if( vips__cache_max_files ) - vips_cache_max_files = - vips__parse_size( vips__cache_max_files ); } } diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index d8bfd35f..b6c367b2 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -614,6 +614,33 @@ vips_lib_version_cb( const gchar *option_name, const gchar *value, exit( 0 ); } +static gboolean +vips_cache_max_cb( const gchar *option_name, const gchar *value, + gpointer data, GError **error ) +{ + vips_cache_set_max( vips__parse_size( value ) ); + + return( TRUE ); +} + +static gboolean +vips_cache_max_memory_cb( const gchar *option_name, const gchar *value, + gpointer data, GError **error ) +{ + vips_cache_set_max_mem( vips__parse_size( value ) ); + + return( TRUE ); +} + +static gboolean +vips_cache_max_files_cb( const gchar *option_name, const gchar *value, + gpointer data, GError **error ) +{ + vips_cache_set_max_files( vips__parse_size( value ) ); + + return( TRUE ); +} + static GOptionEntry option_entries[] = { { "vips-info", 0, G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &vips_lib_info_cb, @@ -652,13 +679,13 @@ static GOptionEntry option_entries[] = { G_OPTION_ARG_NONE, &vips__vector_enabled, N_( "disable vectorised versions of operations" ), NULL }, { "vips-cache-max", 0, 0, - G_OPTION_ARG_STRING, &vips__cache_max, + G_OPTION_ARG_CALLBACK, (gpointer) &vips_cache_max_cb, N_( "cache at most N operations" ), "N" }, { "vips-cache-max-memory", 0, 0, - G_OPTION_ARG_STRING, &vips__cache_max_mem, + G_OPTION_ARG_CALLBACK, (gpointer) &vips_cache_max_memory_cb, N_( "cache at most N bytes in memory" ), "N" }, { "vips-cache-max-files", 0, 0, - G_OPTION_ARG_STRING, &vips__cache_max_files, + G_OPTION_ARG_CALLBACK, (gpointer) &vips_cache_max_files_cb, N_( "allow at most N open files" ), "N" }, { "vips-cache-trace", 0, 0, G_OPTION_ARG_NONE, &vips__cache_trace, diff --git a/libvips/resample/thumbnail.c b/libvips/resample/thumbnail.c index c90c5610..db6d18c5 100644 --- a/libvips/resample/thumbnail.c +++ b/libvips/resample/thumbnail.c @@ -106,6 +106,30 @@ typedef struct _VipsThumbnailClass { G_DEFINE_ABSTRACT_TYPE( VipsThumbnail, vips_thumbnail, VIPS_TYPE_OPERATION ); +static void +vips_thumbnail_dispose( GObject *gobject ) +{ +#ifdef DEBUG + printf( "vips_thumbnail_dispose: " ); + vips_object_print_name( VIPS_OBJECT( gobject ) ); + printf( "\n" ); +#endif /*DEBUG*/ + + G_OBJECT_CLASS( vips_thumbnail_parent_class )->dispose( gobject ); +} + +static void +vips_thumbnail_finalize( GObject *gobject ) +{ +#ifdef DEBUG + printf( "vips_thumbnail_finalize: " ); + vips_object_print_name( VIPS_OBJECT( gobject ) ); + printf( "\n" ); +#endif /*DEBUG*/ + + G_OBJECT_CLASS( vips_thumbnail_parent_class )->finalize( gobject ); +} + /* Calculate the shrink factor, taking into account auto-rotate, the fit mode, * and so on. */ @@ -470,6 +494,8 @@ vips_thumbnail_class_init( VipsThumbnailClass *class ) GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class ); + gobject_class->dispose = vips_thumbnail_dispose; + gobject_class->finalize = vips_thumbnail_finalize; gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; diff --git a/tools/vipsthumbnail.c b/tools/vipsthumbnail.c index e6a184e4..f3fa487b 100644 --- a/tools/vipsthumbnail.c +++ b/tools/vipsthumbnail.c @@ -265,6 +265,10 @@ main( int argc, char **argv ) textdomain( GETTEXT_PACKAGE ); setlocale( LC_ALL, "" ); + /* The operation cache is not useful for processing many files. + vips_cache_set_max( 0 ); + */ + /* On Windows, argv is ascii-only .. use this to get a utf-8 version of * the args. */