/** * vips_cache_operation_buildp: (skip) * @operation: pointer to operation to lookup * * Look up @operation in the cache. If we get a hit, unref @operation, ref the * old one and return that through the argument pointer. * * If we miss, build and add @operation. * * Returns: 0 on success, or -1 on error. */ int vips_cache_operation_buildp( VipsOperation **operation ) { VipsOperation *hit; g_assert( VIPS_IS_OPERATION( *operation ) ); #ifdef VIPS_DEBUG printf( "vips_cache_operation_buildp: " ); vips_object_print_dump( VIPS_OBJECT( *operation ) ); #endif /*VIPS_DEBUG*/ if( (hit = vips_cache_operation_lookup( *operation )) ) { g_object_unref( *operation ); *operation = hit; } else { if( vips_object_build( VIPS_OBJECT( *operation ) ) ) return( -1 ); vips_cache_operation_add( *operation ); } return( 0 ); }
/* Make a VipsObject. */ void vo_object_new( Reduce *rc, const char *name, PElement *required, PElement *optional, PElement *out ) { Vo *vo; Managedgobject *managedgobject; if( !(vo = vo_new( rc, name )) ) reduce_throw( rc ); if( !vo_args( vo, required, optional ) ) { vo_free( vo ); reduce_throw( rc ); } /* Ask the object to construct. */ if( vips_object_build( vo->object ) ) { error_top( _( "VIPS library error." ) ); error_sub( "%s", im_error_buffer() ); im_error_clear(); vo_free( vo ); reduce_throw( rc ); } /* Return the constructed object. */ if( !(managedgobject = managedgobject_new( vo->rc->heap, G_OBJECT( vo->object ) )) ) { vo_free( vo ); reduce_throw( rc ); } PEPUTP( out, ELEMENT_MANAGED, managedgobject ); #ifdef DEBUG { char txt[1000]; VipsBuf buf = VIPS_BUF_STATIC( txt ); vips_object_to_string( vo->object, &buf ); printf( "vo_object_new: built %s\n", vips_buf_all( &buf ) ); } #endif /*DEBUG*/ vo_free( vo ); }
/* Init function for input interpolate. * * This is used as a helper function by the C++ interface, so amke it public. */ int vips__input_interpolate_init( im_object *obj, char *str ) { GType type = g_type_from_name( "VipsInterpolate" ); VipsObjectClass *class = VIPS_OBJECT_CLASS( g_type_class_ref( type ) ); VipsObject *object; g_assert( class ); if( !(object = vips_object_new_from_string( class, str )) ) return( -1 ); if( vips_object_build( object ) ) { g_object_unref( object ); return( -1 ); } *obj = object; return( 0 ); }
/** * vips_cache_operation_buildp: (skip) * @operation: pointer to operation to lookup * * Look up @operation in the cache. If we get a hit, unref @operation, ref the * old one and return that through the argument pointer. * * If we miss, build and add @operation. * * Returns: 0 on success, or -1 on error. */ int vips_cache_operation_buildp( VipsOperation **operation ) { VipsOperation *hit; g_assert( VIPS_IS_OPERATION( *operation ) ); #ifdef VIPS_DEBUG printf( "vips_cache_operation_build: " ); vips_object_print_dump( VIPS_OBJECT( *operation ) ); #endif /*VIPS_DEBUG*/ vips_cache_trim(); g_mutex_lock( vips_cache_lock ); if( (hit = g_hash_table_lookup( vips_cache_table, *operation )) ) { if( vips__cache_trace ) { printf( "vips cache-: " ); vips_object_print_summary( VIPS_OBJECT( hit ) ); } /* Ref before unref in case *operation == hit. */ vips_cache_ref( hit ); g_object_unref( *operation ); *operation = hit; } g_mutex_unlock( vips_cache_lock ); if( !hit ) { if( vips_object_build( VIPS_OBJECT( *operation ) ) ) return( -1 ); /* Has to be after _build() so we can see output args. */ if( vips__cache_trace ) { if( vips_operation_get_flags( *operation ) & VIPS_OPERATION_NOCACHE ) printf( "vips cache : " ); else printf( "vips cache+: " ); vips_object_print_summary( VIPS_OBJECT( *operation ) ); } g_mutex_lock( vips_cache_lock ); if( !(vips_operation_get_flags( *operation ) & VIPS_OPERATION_NOCACHE) ) { vips_cache_ref( *operation ); g_hash_table_insert( vips_cache_table, *operation, *operation ); } g_mutex_unlock( vips_cache_lock ); } return( 0 ); }