mvoe vips7 wrap back to vips7 names

improve cache trace formatting too
This commit is contained in:
John Cupitt 2012-01-06 14:56:24 +00:00
parent d5034b0485
commit 1e3edd7b1e
5 changed files with 50 additions and 67 deletions

View File

@ -700,65 +700,6 @@ vips_wrap7_init( VipsWrap7 *wrap7 )
/* Build a subclass of vips7 for every vips7 operation.
*/
static gboolean
drop_postfix( char *str, const char *postfix )
{
if( vips_ispostfix( str, postfix ) ) {
str[strlen( str ) - strlen( postfix )] = '\0';
return( TRUE );
}
return( FALSE );
}
/* Turn a vips7 name into a nickname. Eg. im_lintra_vec becomes lin.
*/
static void
vips_wrap7_nickname( const char *in, char *out )
{
static const char *dont_drop[] = {
"_set",
};
static const char *drop[] = {
"_vec",
"const",
"tra",
"set",
"_f"
};
int i;
gboolean changed;
/* Copy, chopping off "im_" prefix.
*/
if( vips_isprefix( "im_", in ) )
strcpy( out, in + 3 );
else
strcpy( out, in );
/* Repeatedly drop postfixes while we can. Stop if we see a dont_drop
* postfix.
*/
do {
gboolean found;
found = FALSE;
for( i = 0; i < IM_NUMBER( dont_drop ); i++ )
if( vips_ispostfix( out, dont_drop[i] ) ) {
found = TRUE;
break;
}
if( found )
break;
changed = FALSE;
for( i = 0; i < IM_NUMBER( drop ); i++ )
changed |= drop_postfix( out, drop[i] );
} while( changed );
}
static void
vips_wrap7_subclass_class_init( VipsWrap7Class *class )
{
@ -771,7 +712,6 @@ vips_wrap7_subclass_class_init( VipsWrap7Class *class )
strlen( VIPS_WRAP7_PREFIX );
im_function *fn = im_find_function( name );
char nickname[4096];
int i;
g_assert( !class->fn );
@ -780,8 +720,7 @@ vips_wrap7_subclass_class_init( VipsWrap7Class *class )
gobject_class->set_property = vips_wrap7_object_set_property;
gobject_class->get_property = vips_wrap7_object_get_property;
vips_wrap7_nickname( name, nickname );
vobject_class->nickname = im_strdup( NULL, nickname );
vobject_class->nickname = im_strdup( NULL, name );
vobject_class->description = fn->desc;
class->fn = fn;

View File

@ -92,12 +92,14 @@ void vips_cache_drop_all( void );
int vips_cache_operation_buildp( VipsOperation **operation );
VipsOperation *vips_cache_operation_build( VipsOperation *operation );
void vips_cache_set_max( int max );
void vips_cache_set_max_mem( int max_mem );
void vips_cache_set_max_mem( size_t max_mem );
int vips_cache_get_max( void );
int vips_cache_get_size( void );
size_t vips_cache_get_max_mem( void );
int vips_cache_get_max_files( void );
void vips_cache_set_max_files( int max_files );
void vips_cache_set_dump( gboolean dump );
void vips_cache_set_trace( gboolean trace );
#ifdef __cplusplus
}

View File

@ -619,7 +619,7 @@ vips_cache_operation_buildp( VipsOperation **operation )
if( (hit = g_hash_table_lookup( vips_cache_table, *operation )) ) {
if( vips__cache_trace ) {
printf( "hit %p ", hit );
printf( "vips cache: hit %p\n ", hit );
vips_object_print_summary( VIPS_OBJECT( *operation ) );
}
@ -632,7 +632,7 @@ vips_cache_operation_buildp( VipsOperation **operation )
}
else {
if( vips__cache_trace ) {
printf( "miss + build %p ", hit );
printf( "vips cache: miss %p\n ", *operation );
vips_object_print_summary( VIPS_OBJECT( *operation ) );
}
@ -678,6 +678,7 @@ vips_cache_operation_build( VipsOperation *operation )
/**
* vips_cache_set_max:
* @max: maximum number of operation to cache
*
* Set the maximum number of operations we keep in cache.
*/
@ -690,6 +691,7 @@ vips_cache_set_max( int max )
/**
* vips_cache_set_max_mem:
* @max_mem: maximum amount of tracked memory we use
*
* Set the maximum amount of tracked memory we allow before we start dropping
* cached operations. See vips_tracked_get_mem().
@ -697,7 +699,7 @@ vips_cache_set_max( int max )
* See also: vips_tracked_get_mem().
*/
void
vips_cache_set_max_mem( int max_mem )
vips_cache_set_max_mem( size_t max_mem )
{
vips_cache_max_mem = max_mem;
vips_cache_trim();
@ -766,6 +768,7 @@ vips_cache_get_max_files( void )
/**
* vips_cache_set_max_files:
* @max_files: max open files we allow
*
* Set the maximum number of tracked files we allow before we start dropping
* cached operations. See vips_tracked_get_files().
@ -778,3 +781,31 @@ vips_cache_set_max_files( int max_files )
vips_cache_max_files = max_files;
vips_cache_trim();
}
/**
* vips_cache_set_dump:
* @dump: if %TRUE, dump the operation cache on exit
*
* Handy for debugging. Print the operation cache to stdout just before exit.
*
* See also: vips_cache_set_trace().
*/
void
vips_cache_set_dump( gboolean dump )
{
vips__cache_dump = dump;
}
/**
* vips_cache_set_trace:
* @trace: if %TRUE, trace the operation cache
*
* Handy for debugging. Print operation cache actions to stdout as we run.
*
* See also: vips_cache_set_dump().
*/
void
vips_cache_set_trace( gboolean trace )
{
vips__cache_trace = trace;
}

View File

@ -5,6 +5,10 @@ logging.basicConfig(level = logging.DEBUG)
from vips8 import vips
from gi.repository import Vips
Vips.cache_set_trace(True)
try:
a = vips.Image("/home/john/pics/babe.poop")
except vips.Error, e:
@ -23,3 +27,5 @@ print 'out =', out
out = a.add(b)
print 'out =', out
out = a.linear(1, 2)

View File

@ -43,7 +43,10 @@ def _call_base(name, self, required, optional):
logging.debug('_call_base name=%s, self=%s, required=%s optional=%s' %
(name, self, required, optional))
op = Vips.Operation.new(name)
try:
op = Vips.Operation.new(name)
except TypeError, e:
raise Error('No such operator.')
# find all the args for this op, sort into priority order
args = [Argument(op, x) for x in op.props]
@ -77,6 +80,8 @@ def _call_base(name, self, required, optional):
(name, len(required_input), len(required)))
for i in range(len(required_input)):
print 'assigning', required[i], 'to', required_input[i].name
print required_input[i].name, 'needs a', required_input[i].prop.value_type
op.props.__setattr__(required_input[i].name, required[i])
# find all optional, unassigned input args ... just need the names