From f2d9001ccef8304c75dbeaf1bf4fa04cb9d4d6c8 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 2 Nov 2011 09:22:30 +0000 Subject: [PATCH] rename function members some function members were not named with a trailing _fn, causing confusion --- TODO | 16 +++++++++++ libvips/include/vips/generate.h | 6 ++--- libvips/include/vips/image.h | 6 ++--- libvips/iofuncs/generate.c | 34 ++++++++++++------------ libvips/iofuncs/image.c | 18 ++++++------- libvips/iofuncs/region.c | 20 +++++++------- libvips/iofuncs/sink.c | 47 +++++++++++++++++---------------- 7 files changed, 82 insertions(+), 65 deletions(-) diff --git a/TODO b/TODO index f51454a3..4d6a44bf 100644 --- a/TODO +++ b/TODO @@ -31,6 +31,22 @@ it's the 'stop' member of SinkThreadState return( 0 ); } +argh we have ->stop (a bool) and ->stop (a function) + +rename the function as stop_fn + +sstate is the "state" member of VipsThread + +which is created by the ->start member of the thread + +which is set by vips_threadpool_run() + +which is vips_thread_state_new(), see vips_sink_memory() + +which creates a VipsThreadState + + +so .. move ->stop from SinkThreadState into the base class, VipsThreadState diff --git a/libvips/include/vips/generate.h b/libvips/include/vips/generate.h index 6d207a5c..56debe57 100644 --- a/libvips/include/vips/generate.h +++ b/libvips/include/vips/generate.h @@ -44,11 +44,11 @@ typedef int (*VipsGenerateFn)( VipsRegion *out, void *seq, void *a, void *b, gboolean *stop ); typedef int (*VipsStopFn)( void *seq, void *a, void *b ); int vips_sink( VipsImage *im, - VipsStartFn start, VipsGenerateFn generate, VipsStopFn stop, + VipsStartFn start_fn, VipsGenerateFn generate_fn, VipsStopFn stop_fn, void *a, void *b ); int vips_sink_tile( VipsImage *im, int tile_width, int tile_height, - VipsStartFn start, VipsGenerateFn generate, VipsStopFn stop, + VipsStartFn start_fn, VipsGenerateFn generate_fn, VipsStopFn stop_fn, void *a, void *b ); typedef void (*VipsSinkNotify)( VipsImage *im, VipsRect *rect, void *a ); @@ -69,7 +69,7 @@ VipsImage **vips_allocate_input_array( VipsImage *out, ... ) __attribute__((sentinel)); int vips_image_generate( VipsImage *im, - VipsStartFn start, VipsGenerateFn generate, VipsStopFn stop, + VipsStartFn start_fn, VipsGenerateFn generate_fn, VipsStopFn stop_fn, void *a, void *b ); diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index df9c6849..d2902a17 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -297,9 +297,9 @@ typedef struct _VipsImage { /* Partial image stuff. All these fields are initialised * to NULL and ignored unless set by vips_image_generate() etc. */ - void *(*start)(); /* user-supplied start function */ - int (*generate)(); /* user-supplied generate function */ - int (*stop)(); /* user-supplied stop function */ + void *(*start_fn)(); /* user-supplied start function */ + int (*generate_fn)(); /* user-supplied generate function */ + int (*stop_fn)(); /* user-supplied stop function */ void *client1; /* user arguments */ void *client2; GMutex *sslock; /* start-stop lock */ diff --git a/libvips/iofuncs/generate.c b/libvips/iofuncs/generate.c index f208d129..08568665 100644 --- a/libvips/iofuncs/generate.c +++ b/libvips/iofuncs/generate.c @@ -567,9 +567,9 @@ write_vips( VipsRegion *region, VipsRect *area, void *a, void *b ) /** * vips_image_generate: * @image: generate this image - * @start: start sequences with this function - * @generate: generate pixels with this function - * @stop: stop sequences with this function + * @start_fn: start sequences with this function + * @generate_fn: generate pixels with this function + * @stop_fn: stop sequences with this function * @a: user data * @b: user data * @@ -591,14 +591,14 @@ write_vips( VipsRegion *region, VipsRect *area, void *a, void *b ) */ int vips_image_generate( VipsImage *image, - VipsStartFn start, VipsGenerateFn generate, VipsStopFn stop, + VipsStartFn start_fn, VipsGenerateFn generate_fn, VipsStopFn stop_fn, void *a, void *b ) { int res; VIPS_DEBUG_MSG( "vips_image_generate: %p\n", image ); - g_assert( generate ); + g_assert( generate_fn ); g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); if( !image->hint_set ) { @@ -618,17 +618,17 @@ vips_image_generate( VipsImage *image, case VIPS_IMAGE_PARTIAL: /* Output to partial image. Just attach functions and return. */ - if( image->generate || - image->start || - image->stop ) { + if( image->generate_fn || + image->start_fn || + image->stop_fn ) { vips_error( "VipsImage", "%s", _( "generate() called twice" ) ); return( -1 ); } - image->start = start; - image->generate = generate; - image->stop = stop; + image->start_fn = start_fn; + image->generate_fn = generate_fn; + image->stop_fn = stop_fn; image->client1 = a; image->client2 = b; @@ -643,9 +643,9 @@ vips_image_generate( VipsImage *image, case VIPS_IMAGE_OPENOUT: /* Eval now .. sanity check. */ - if( image->generate || - image->start || - image->stop ) { + if( image->generate_fn || + image->start_fn || + image->stop_fn ) { vips_error( "VipsImage", "%s", _( "generate() called twice" ) ); return( -1 ); @@ -653,9 +653,9 @@ vips_image_generate( VipsImage *image, /* Attach callbacks. */ - image->start = start; - image->generate = generate; - image->stop = stop; + image->start_fn = start_fn; + image->generate_fn = generate_fn; + image->stop_fn = stop_fn; image->client1 = a; image->client2 = b; diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 091bbef2..69f4f01d 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -185,9 +185,9 @@ vips_image_finalize( GObject *gobject ) /* Junk generate functions. */ - image->start = NULL; - image->generate = NULL; - image->stop = NULL; + image->start_fn = NULL; + image->generate_fn = NULL; + image->stop_fn = NULL; image->client1 = NULL; image->client2 = NULL; @@ -2095,7 +2095,7 @@ vips_image_wio_output( VipsImage *image ) case VIPS_IMAGE_PARTIAL: /* Make sure nothing is attached. */ - if( image->generate ) { + if( image->generate_fn ) { vips_error( "vips_image_wio_output", "%s", _( "image already written" ) ); return( -1 ); @@ -2213,16 +2213,16 @@ vips_image_pio_input( VipsImage *image ) /* Should be no generate functions now. */ - image->start = NULL; - image->generate = NULL; - image->stop = NULL; + image->start_fn = NULL; + image->generate_fn = NULL; + image->stop_fn = NULL; break; case VIPS_IMAGE_PARTIAL: /* Should have had generate functions attached. */ - if( !image->generate ) { + if( !image->generate_fn ) { vips_error( "vips_image_pio_input", "%s", _( "no image data" ) ); return( -1 ); @@ -2284,7 +2284,7 @@ vips_image_pio_output( VipsImage *image ) break; case VIPS_IMAGE_PARTIAL: - if( image->generate ) { + if( image->generate_fn ) { vips_error( "im_poutcheck", "%s", _( "image already written" ) ); return( -1 ); diff --git a/libvips/iofuncs/region.c b/libvips/iofuncs/region.c index 27e3081d..f13ade12 100644 --- a/libvips/iofuncs/region.c +++ b/libvips/iofuncs/region.c @@ -201,10 +201,10 @@ vips__region_start( VipsRegion *region ) { VipsImage *image = region->im; - if( !region->seq && image->start ) { + if( !region->seq && image->start_fn ) { g_mutex_lock( image->sslock ); - region->seq = - image->start( image, image->client1, image->client2 ); + region->seq = image->start_fn( image, + image->client1, image->client2 ); g_mutex_unlock( image->sslock ); if( !region->seq ) { @@ -225,11 +225,11 @@ vips__region_stop( VipsRegion *region ) { IMAGE *image = region->im; - if( region->seq && image->stop ) { + if( region->seq && image->stop_fn ) { int result; g_mutex_lock( image->sslock ); - result = image->stop( region->seq, + result = image->stop_fn( region->seq, image->client1, image->client2 ); g_mutex_unlock( image->sslock ); @@ -321,7 +321,7 @@ vips_region_sanity( VipsObject *object, VipsBuf *buf ) case VIPS_IMAGE_PARTIAL: /* Start and stop can be NULL, but not generate. */ - if( !region->im->generate ) + if( !region->im->generate_fn ) vips_buf_appends( buf, "generate NULL in partial\n" ); break; @@ -796,7 +796,7 @@ int vips_region_fill( VipsRegion *reg, VipsRect *r, VipsRegionFillFn fn, void *a ) { g_assert( reg->im->dtype == VIPS_IMAGE_PARTIAL ); - g_assert( reg->im->generate ); + g_assert( reg->im->generate_fn ); /* Should have local memory. */ @@ -986,7 +986,7 @@ vips_region_generate( VipsRegion *reg ) /* Ask for evaluation. */ - if( im->generate( reg, reg->seq, im->client1, im->client2 ) ) + if( im->generate_fn( reg, reg->seq, im->client1, im->client2 ) ) return( -1 ); return( 0 ); @@ -1093,7 +1093,7 @@ vips_region_prepare_to_generate( VipsRegion *reg, IMAGE *im = reg->im; char *p; - if( !im->generate ) { + if( !im->generate_fn ) { vips_error( "vips_region_prepare_to", "%s", _( "incomplete header" ) ); return( -1 ); @@ -1248,7 +1248,7 @@ vips_region_prepare_to( VipsRegion *reg, /* Could be either input or output. If there is a generate * function, we are outputting. */ - if( im->generate ) { + if( im->generate_fn ) { if( vips_region_prepare_to_generate( reg, dest, &final, x, y ) ) return( -1 ); diff --git a/libvips/iofuncs/sink.c b/libvips/iofuncs/sink.c index 1be75273..3a73d6f6 100644 --- a/libvips/iofuncs/sink.c +++ b/libvips/iofuncs/sink.c @@ -61,9 +61,9 @@ typedef struct _Sink { /* Call params. */ - VipsStartFn start; - VipsGenerateFn generate; - VipsStopFn stop; + VipsStartFn start_fn; + VipsGenerateFn generate_fn; + VipsStopFn stop_fn; void *a; void *b; } Sink; @@ -99,10 +99,10 @@ G_DEFINE_TYPE( SinkThreadState, sink_thread_state, VIPS_TYPE_THREAD_STATE ); static int sink_call_stop( Sink *sink, SinkThreadState *state ) { - if( state->seq && sink->stop ) { + if( state->seq && sink->stop_fn ) { VIPS_DEBUG_MSG( "sink_call_stop: state = %p\n", state ); - if( sink->stop( state->seq, sink->a, sink->b ) ) { + if( sink->stop_fn( state->seq, sink->a, sink->b ) ) { SinkBase *sink_base = (SinkBase *) sink; vips_error( "vips_sink", @@ -134,10 +134,10 @@ sink_thread_state_dispose( GObject *gobject ) static int sink_call_start( Sink *sink, SinkThreadState *state ) { - if( !state->seq && sink->start ) { + if( !state->seq && sink->start_fn ) { VIPS_DEBUG_MSG( "sink_call_start: state = %p\n", state ); - state->seq = sink->start( sink->t, sink->a, sink->b ); + state->seq = sink->start_fn( sink->t, sink->a, sink->b ); if( !state->seq ) { SinkBase *sink_base = (SinkBase *) sink; @@ -221,17 +221,17 @@ vips_sink_base_init( SinkBase *sink_base, VipsImage *image ) static int sink_init( Sink *sink, VipsImage *image, - VipsStartFn start, VipsGenerateFn generate, VipsStopFn stop, + VipsStartFn start_fn, VipsGenerateFn generate_fn, VipsStopFn stop_fn, void *a, void *b ) { - g_assert( generate ); + g_assert( generate_fn ); vips_sink_base_init( &sink->sink_base, image ); sink->t = NULL; - sink->start = start; - sink->generate = generate; - sink->stop = stop; + sink->start_fn = start_fn; + sink->generate_fn = generate_fn; + sink->stop_fn = stop_fn; sink->a = a; sink->b = b; @@ -299,7 +299,7 @@ sink_work( VipsThreadState *state, void *a ) Sink *sink = (Sink *) a; if( vips_region_prepare( sstate->reg, &state->pos ) || - sink->generate( sstate->reg, sstate->seq, + sink->generate_fn( sstate->reg, sstate->seq, sink->a, sink->b, &sstate->stop ) ) return( -1 ); @@ -330,9 +330,9 @@ vips_sink_base_progress( void *a ) * @im: scan over this image * @tile_width: tile width * @tile_height: tile height - * @start: start sequences with this function - * @generate: generate pixels with this function - * @stop: stop sequences with this function + * @start_fn: start sequences with this function + * @generate_fn: generate pixels with this function + * @stop_fn: stop sequences with this function * @a: user data * @b: user data * @@ -352,7 +352,7 @@ vips_sink_base_progress( void *a ) int vips_sink_tile( VipsImage *im, int tile_width, int tile_height, - VipsStartFn start, VipsGenerateFn generate, VipsStopFn stop, + VipsStartFn start_fn, VipsGenerateFn generate_fn, VipsStopFn stop_fn, void *a, void *b ) { Sink sink; @@ -365,7 +365,7 @@ vips_sink_tile( VipsImage *im, */ im->Bbits = vips_format_sizeof( im->BandFmt ) << 3; - if( sink_init( &sink, im, start, generate, stop, a, b ) ) + if( sink_init( &sink, im, start_fn, generate_fn, stop_fn, a, b ) ) return( -1 ); if( tile_width > 0 ) { @@ -395,9 +395,9 @@ vips_sink_tile( VipsImage *im, /** * vips_sink: * @im: scan over this image - * @start: start sequences with this function - * @generate: generate pixels with this function - * @stop: stop sequences with this function + * @start_fn: start sequences with this function + * @generate_fn: generate pixels with this function + * @stop_fn: stop sequences with this function * @a: user data * @b: user data * @@ -414,8 +414,9 @@ vips_sink_tile( VipsImage *im, */ int vips_sink( VipsImage *im, - VipsStartFn start, VipsGenerateFn generate, VipsStopFn stop, + VipsStartFn start_fn, VipsGenerateFn generate_fn, VipsStopFn stop_fn, void *a, void *b ) { - return( vips_sink_tile( im, -1, -1, start, generate, stop, a, b ) ); + return( vips_sink_tile( im, -1, -1, + start_fn, generate_fn, stop_fn, a, b ) ); }