From a6dc0b6feaa606f89f1e9a0f8e15946f72487f16 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 4 Jan 2012 13:50:10 +0000 Subject: [PATCH] operation cache works from Python --- TODO | 2 -- libvips/iofuncs/cache.c | 7 +++-- libvips/iofuncs/operation.c | 55 ++++++++++++++++++++++++++++++++++--- python/try.py | 17 +++++------- 4 files changed, 63 insertions(+), 18 deletions(-) diff --git a/TODO b/TODO index 755792af..d1f241a9 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -- test Vips.cache_operation_build() - - grep for other vips_class_find() problems: do we use it for simple class diff --git a/libvips/iofuncs/cache.c b/libvips/iofuncs/cache.c index 3e85d0b0..e5e81a87 100644 --- a/libvips/iofuncs/cache.c +++ b/libvips/iofuncs/cache.c @@ -46,8 +46,8 @@ */ /* -#define VIPS_DEBUG */ +#define VIPS_DEBUG #ifdef HAVE_CONFIG_H #include @@ -607,7 +607,10 @@ vips_cache_operation_buildp( VipsOperation **operation ) g_assert( VIPS_IS_OPERATION( *operation ) ); - VIPS_DEBUG_MSG( "vips_cache_operation_build: %p\n", *operation ); +#ifdef VIPS_DEBUG + printf( "vips_cache_operation_build: " ); + vips_object_print_summary( VIPS_OBJECT( *operation ) ); +#endif /*VIPS_DEBUG*/ vips_cache_init(); diff --git a/libvips/iofuncs/operation.c b/libvips/iofuncs/operation.c index 7d963e97..55477153 100644 --- a/libvips/iofuncs/operation.c +++ b/libvips/iofuncs/operation.c @@ -153,7 +153,8 @@ vips_operation_print_usage( VipsOperationClass *class, VipsBuf *buf ) static void * vips_operation_call_argument( VipsObject *object, GParamSpec *pspec, VipsArgumentClass *argument_class, - VipsArgumentInstance *argument_instance ) + VipsArgumentInstance *argument_instance, + void *a, void *b ) { VipsArgument *argument = (VipsArgument *) argument_class; @@ -181,11 +182,57 @@ vips_operation_print( VipsObject *object, VipsBuf *buf ) printf( "%s args:\n", object_class->nickname ); vips_argument_map( VIPS_OBJECT( operation ), - (VipsArgumentMapFn) vips_operation_call_argument, NULL, NULL ); + vips_operation_call_argument, NULL, NULL ); VIPS_OBJECT_CLASS( vips_operation_parent_class )->print( object, buf ); } +static void * +vips_operation_vips_operation_print_summary_arg( VipsObject *object, + GParamSpec *pspec, + VipsArgumentClass *argument_class, + VipsArgumentInstance *argument_instance, + void *a, void *b ) +{ + VipsBuf *buf = (VipsBuf *) a; + + /* Just assigned required input construct args + */ + if( (argument_class->flags & VIPS_ARGUMENT_REQUIRED) && + (argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) && + (argument_class->flags & VIPS_ARGUMENT_INPUT) && + argument_instance->assigned ) { + const char *name = g_param_spec_get_name( pspec ); + GType type = G_PARAM_SPEC_VALUE_TYPE( pspec ); + + GValue gvalue = { 0, }; + char *str; + + g_value_init( &gvalue, type ); + g_object_get_property( G_OBJECT( object ), name, &gvalue ); + str = g_strdup_value_contents( &gvalue ); + vips_buf_appendf( buf, " %s", str ); + g_free( str ); + g_value_unset( &gvalue ); + } + + return( NULL ); +} + +static void +vips_operation_print_summary( VipsObject *object, VipsBuf *buf ) +{ + VipsOperation *operation = VIPS_OPERATION( object ); + VipsObjectClass *object_class = VIPS_OBJECT_GET_CLASS( object ); + + vips_buf_appendf( buf, "%s", object_class->nickname ); + vips_argument_map( VIPS_OBJECT( operation ), + vips_operation_vips_operation_print_summary_arg, buf, NULL ); + + VIPS_OBJECT_CLASS( vips_operation_parent_class )-> + print_summary( object, buf ); +} + static void vips_operation_class_init( VipsOperationClass *class ) { @@ -198,6 +245,7 @@ vips_operation_class_init( VipsOperationClass *class ) vobject_class->nickname = "operation"; vobject_class->description = _( "operations" ); vobject_class->print = vips_operation_print; + vobject_class->print_summary = vips_operation_print_summary; class->print_usage = vips_operation_print_usage; } @@ -705,8 +753,7 @@ vips_call_options_set( const gchar *option_name, const gchar *value, VIPS_DEBUG_MSG( "\tGValue %s = %s\n", g_param_spec_get_name( pspec ), str ); g_free( str ); - - g_object_unref( &gvalue ); + g_value_unset( &gvalue ); } #endif /*VIPS_DEBUG*/ } diff --git a/python/try.py b/python/try.py index a9915a47..3e62beef 100755 --- a/python/try.py +++ b/python/try.py @@ -42,11 +42,12 @@ for prop in op.props: op.props.left = a op.props.right = a -if op.build() != 0: +op2 = Vips.cache_operation_build(op) +if op2 == None: print Vips.error_buffer() sys.exit(-1) -out = op.props.out -op.unref_outputs() +out = op2.props.out +op2.unref_outputs() print 'out.get_format() =', out.get_format() print 'out.props.format =', out.props.format @@ -54,12 +55,8 @@ print 'out.props.format =', out.props.format out.write_to_file("x.v") print 'starting shutdown ...' -del a -del op -del out - # sometimes have to do several GCs to get them all, not sure why -for i in range(10): - gc.collect () -print 'shutdown!' +#for i in range(10): +# gc.collect () +#print 'shutdown!'