operation cache works from Python

This commit is contained in:
John Cupitt 2012-01-04 13:50:10 +00:00
parent 6f82f1ad61
commit a6dc0b6fea
4 changed files with 63 additions and 18 deletions

2
TODO
View File

@ -1,5 +1,3 @@
- test Vips.cache_operation_build()
- grep for other vips_class_find() problems: do we use it for simple class

View File

@ -46,8 +46,8 @@
*/
/*
#define VIPS_DEBUG
*/
#define VIPS_DEBUG
#ifdef HAVE_CONFIG_H
#include <config.h>
@ -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();

View File

@ -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*/
}

View File

@ -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!'