From 904803510db025d040914890a96bc8b8c5d94df8 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 21 Oct 2014 09:27:34 +0100 Subject: [PATCH] box/unbox hooks in C API should help us pass C++ objects as args --- cplusplus/VImage.cc | 9 +++++++-- libvips/include/vips/operation.h | 14 ++++++++++++++ libvips/iofuncs/operation.c | 15 ++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/cplusplus/VImage.cc b/cplusplus/VImage.cc index 187f5baf..3875ed52 100644 --- a/cplusplus/VImage.cc +++ b/cplusplus/VImage.cc @@ -70,6 +70,11 @@ void thread_shutdown() vips_thread_shutdown(); } + + + + + // see vips_image_new_from_file() VImage::VImage( const char *name, ... ) __attribute__((sentinel)) throw( VError ) @@ -140,7 +145,7 @@ void VImage::write( const char *name, ... ) va_start( ap, name ); result = vips_call_split_option_string( operation_name, option_string, - ap, image, filename ); + ap, this.im, filename ); va_end( ap ); if( result ) @@ -165,7 +170,7 @@ void *VImage::write( const char *suffix, size_t *size, ... ) va_start( ap, size ); result = vips_call_split_option_string( operation_name, option_string, - ap, in, &blob ); + ap, this.im, &blob ); va_end( ap ); if( result ) diff --git a/libvips/include/vips/operation.h b/libvips/include/vips/operation.h index d35ae1c9..53dd63b5 100644 --- a/libvips/include/vips/operation.h +++ b/libvips/include/vips/operation.h @@ -74,6 +74,20 @@ typedef struct _VipsOperation { */ int pixels; + /* Get and set functions, used by eg. the C++ interface to box and + * unbox VImage. + */ + + /* The value has been read from the VipsOperation and written to the arg + * pointer. @arg is eg. gboolean* for a bool value. + */ + void (*collect_get)( GParamSpec *pspec, void *arg ); + + /* The value has been read from argv into a GValue. Do any + * boxing/unboxing before the GValue is used to set the property. + */ + void (*collect_set)( GParamSpec *pspec, GValue *value ); + } VipsOperation; typedef struct _VipsOperationClass { diff --git a/libvips/iofuncs/operation.c b/libvips/iofuncs/operation.c index a540c7df..5f8aca87 100644 --- a/libvips/iofuncs/operation.c +++ b/libvips/iofuncs/operation.c @@ -603,6 +603,9 @@ vips_operation_set_valist_required( VipsOperation *operation, va_list ap ) } #endif /*VIPS_DEBUG */ + if( operation->collect_set ) + operation->collect_set( pspec, &value ); + g_object_set_property( G_OBJECT( operation ), g_param_spec_get_name( pspec ), &value ); @@ -645,7 +648,7 @@ vips_operation_get_valist_required( VipsOperation *operation, va_list ap ) /* It'd be nice to be able to test for arg being a * valid gobject pointer, since passing in a valid - * pointer, and having us destroy it, is a common + * pointer (and having us destroy it) is a common * error and a cause of hard-to-find leaks. * * Unfortunately, G_IS_OBJECT() can't be given an @@ -667,6 +670,11 @@ vips_operation_get_valist_required( VipsOperation *operation, va_list ap ) g_object_unref( object ); } + /* Do any boxing/unboxing. + */ + if( operation->collect_get ) + operation->collect_get( pspec, arg ); + VIPS_ARGUMENT_COLLECT_END } } VIPS_ARGUMENT_FOR_ALL_END @@ -725,6 +733,11 @@ vips_operation_get_valist_optional( VipsOperation *operation, va_list ap ) object = *((GObject **) arg); g_object_unref( object ); } + + /* Do any boxing/unboxing. + */ + if( operation->collect_get ) + operation->collect_get( pspec, arg ); } VIPS_ARGUMENT_COLLECT_END