From 8abcae3abc6ac29db51e559cba18f62562ff872f Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 18 Jun 2020 14:21:43 +0200 Subject: [PATCH] Avoid using vips7 symbols --- libvips/foreign/radiance.c | 2 +- libvips/iofuncs/init.c | 42 ++++++++++- libvips/resample/transform.c | 27 +++---- test/test-suite/test_iofuncs.py | 2 + tools/vips.c | 46 +++++++++++- tools/vipsedit.c | 122 +++++++++++++++++--------------- 6 files changed, 166 insertions(+), 75 deletions(-) diff --git a/libvips/foreign/radiance.c b/libvips/foreign/radiance.c index a71b1bff..d5ba070b 100644 --- a/libvips/foreign/radiance.c +++ b/libvips/foreign/radiance.c @@ -1168,7 +1168,7 @@ vips__rad_save( VipsImage *in, VipsTarget *target ) #endif /*DEBUG*/ if( vips_image_pio_input( in ) || - vips_check_coding_rad( "vips2rad", in ) ) + vips_check_coding( "vips2rad", in, VIPS_CODING_RAD ) ) return( -1 ); if( !(write = write_new( in, target )) ) return( -1 ); diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index e1be8f21..1ea409f6 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -98,7 +98,10 @@ #include #include #include + +#if VIPS_ENABLE_DEPRECATED #include +#endif /* abort() on the first warning or error. */ @@ -312,6 +315,32 @@ set_stacksize( guint64 size ) #endif /*HAVE_PTHREAD_DEFAULT_NP*/ } +static void +vips_verbose( void ) +{ + /* Older glibs were showing G_LOG_LEVEL_{INFO,DEBUG} messages + * by default + */ +#if GLIB_CHECK_VERSION ( 2, 31, 0 ) + const char *old; + + old = g_getenv( "G_MESSAGES_DEBUG" ); + + if( !old ) { + g_setenv( "G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE ); + } + else if( !g_str_equal( old, "all" ) && + !g_strrstr( old, G_LOG_DOMAIN ) ) { + char *new; + + new = g_strconcat( old, " ", G_LOG_DOMAIN, NULL ); + g_setenv( "G_MESSAGES_DEBUG", new, TRUE ); + + g_free( new ); + } +#endif /*GLIB_CHECK_VERSION( 2, 31, 0 )*/ +} + /** * vips_init: * @argv0: name of application @@ -440,7 +469,7 @@ vips_init( const char *argv0 ) #else if( g_getenv( "VIPS_INFO" ) ) #endif - vips_info_set( TRUE ); + vips_verbose(); if( g_getenv( "VIPS_PROFILE" ) ) vips_profile_set( TRUE ); if( g_getenv( "VIPS_LEAK" ) ) @@ -466,7 +495,10 @@ vips_init( const char *argv0 ) (void) vips_target_custom_get_type(); vips__meta_init_types(); vips__interpolate_init(); + +#if VIPS_ENABLE_DEPRECATED im__format_init(); +#endif /* Start up operator cache. */ @@ -499,6 +531,7 @@ vips_init( const char *argv0 ) (void) vips_load_plugins( "%s/vips-plugins-%d.%d", libdir, VIPS_MAJOR_VERSION, VIPS_MINOR_VERSION ); +#if VIPS_ENABLE_DEPRECATED /* Load up any vips7 plugins in the vips libdir. We don't error on * failure, it's too annoying to have VIPS refuse to start because of * a broken plugin. @@ -516,6 +549,7 @@ vips_init( const char *argv0 ) g_warning( "%s", vips_error_buffer() ); vips_error_clear(); } +#endif /* Get the run-time compiler going. */ @@ -554,7 +588,7 @@ vips_init( const char *argv0 ) #else if( g_getenv( "VIPS_WARNING" ) ) #endif - g_log_set_handler( "VIPS", G_LOG_LEVEL_WARNING, + g_log_set_handler( G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, empty_log_handler, NULL ); /* Set a minimum stacksize, if we can. @@ -659,7 +693,9 @@ vips_shutdown( void ) vips_cache_drop_all(); +#if VIPS_ENABLE_DEPRECATED im_close_plugins(); +#endif /* Mustn't run this more than once. Don't use the VIPS_GATE macro, * since we don't for gate start. @@ -717,7 +753,7 @@ static gboolean vips_lib_info_cb( const gchar *option_name, const gchar *value, gpointer data, GError **error ) { - vips_info_set( TRUE ); + vips_verbose(); return( TRUE ); } diff --git a/libvips/resample/transform.c b/libvips/resample/transform.c index 5d6af3dc..aaad7c34 100644 --- a/libvips/resample/transform.c +++ b/libvips/resample/transform.c @@ -43,26 +43,29 @@ #include #include +/* DBL_MIN is smallest *normalized* double precision float */ +#define TOO_SMALL 2.0 * DBL_MIN + /* Calculate the inverse transformation. */ int vips__transform_calc_inverse( VipsTransformation *trn ) { - DOUBLEMASK *msk, *msk2; + double det = trn->a * trn->d - trn->b * trn->c; - if( !(msk = im_create_dmaskv( "boink", 2, 2, - trn->a, trn->b, trn->c, trn->d )) ) - return( -1 ); - if( !(msk2 = im_matinv( msk, "boink2" )) ) { - (void) im_free_dmask( msk ); + if( fabs( det ) < TOO_SMALL ) { + /* divisor is near zero */ + vips_error( "vips__transform_calc_inverse", + "%s", _( "singular or near-singular matrix" ) ); return( -1 ); } - trn->ia = msk2->coeff[0]; - trn->ib = msk2->coeff[1]; - trn->ic = msk2->coeff[2]; - trn->id = msk2->coeff[3]; - (void) im_free_dmask( msk ); - (void) im_free_dmask( msk2 ); + + double tmp = 1.0 / det; + + trn->ia = tmp * trn->d; + trn->ib = -tmp * trn->b; + trn->ic = -tmp * trn->c; + trn->id = tmp * trn->a; return( 0 ); } diff --git a/test/test-suite/test_iofuncs.py b/test/test-suite/test_iofuncs.py index 4d076f0e..2a02a48d 100644 --- a/test/test-suite/test_iofuncs.py +++ b/test/test-suite/test_iofuncs.py @@ -8,6 +8,8 @@ from helpers import assert_equal_objects class TestIofuncs: # test the vips7 filename splitter ... this is very fragile and annoying # code with lots of cases + + @pytest.mark.xfail(raises=AttributeError, reason="uses deprecated symbols") def test_split7(self): def split(path): filename7 = pyvips.path_filename7(path) diff --git a/tools/vips.c b/tools/vips.c index a6432528..6d0990be 100644 --- a/tools/vips.c +++ b/tools/vips.c @@ -42,6 +42,9 @@ * - parse options in two passes (thanks Haida) * 26/11/17 * - remove throw() decls, they are now deprecated everywhere + * 18/6/20 kleisauke + * - avoid using vips7 symbols + * - remove deprecated vips7 C++ generator */ /* @@ -92,9 +95,12 @@ #include #include -#include #include +#if VIPS_ENABLE_DEPRECATED +#include +#endif + #ifdef OS_WIN32 #define strcasecmp(a,b) _stricmp(a,b) #endif @@ -180,6 +186,7 @@ static GOptionEntry main_option[] = { { NULL } }; +#if VIPS_ENABLE_DEPRECATED typedef void *(*map_name_fn)( im_function * ); /* Loop over a package. @@ -241,13 +248,18 @@ list_function( im_function *func ) return( NULL ); } +#endif static int print_list( int argc, char **argv ) { +#if VIPS_ENABLE_DEPRECATED if( !argv[0] || strcmp( argv[0], "packages" ) == 0 ) im_map_packages( (VSListMap2Fn) list_package, NULL ); else if( strcmp( argv[0], "classes" ) == 0 ) +#else + if( !argv[0] || strcmp( argv[0], "classes" ) == 0 ) +#endif vips_type_map_all( g_type_from_name( "VipsObject" ), (VipsTypeMapFn) list_class, NULL ); else if( g_type_from_name( argv[0] ) && @@ -256,13 +268,18 @@ print_list( int argc, char **argv ) (VipsTypeMapFn) list_class, NULL ); } else { +#if VIPS_ENABLE_DEPRECATED if( map_name( argv[0], list_function ) ) vips_error_exit( "unknown package \"%s\"", argv[0] ); +#else + vips_error_exit( "unknown operation \"%s\"", argv[0] ); +#endif } return( 0 ); } +#if VIPS_ENABLE_DEPRECATED /* Print "ln -s" lines for this package. */ static void * @@ -301,6 +318,7 @@ has_print( im_function *fn ) return( 0 ); } +#endif static int isvips( const char *name ) @@ -313,6 +331,7 @@ isvips( const char *name ) return( vips_isprefix( "vips", name ) ); } +#if VIPS_ENABLE_DEPRECATED /* Print a usage string from an im_function descriptor. */ static void @@ -382,6 +401,7 @@ usage( im_function *fn ) fprintf( stderr, "\n" ); } +#endif static int print_help( int argc, char **argv ) @@ -406,10 +426,16 @@ static GOptionEntry empty_options[] = { }; static ActionEntry actions[] = { +#if VIPS_ENABLE_DEPRECATED { "list", N_( "list classes|packages|all|package-name|operation-name" ), +#else + { "list", N_( "list classes|all|operation-name" ), +#endif &empty_options[0], print_list }, +#if VIPS_ENABLE_DEPRECATED { "links", N_( "generate links for vips/bin" ), &empty_options[0], print_links }, +#endif { "help", N_( "list possible actions" ), &empty_options[0], print_help }, }; @@ -489,14 +515,16 @@ main( int argc, char **argv ) GOptionGroup *main_group; GOptionGroup *group; VipsOperation *operation; +#if VIPS_ENABLE_DEPRECATED im_function *fn; +#endif int i, j; gboolean handled; GError *error = NULL; if( VIPS_INIT( argv[0] ) ) - vips_error_exit( NULL ); + vips_error_exit( NULL ); textdomain( GETTEXT_PACKAGE ); setlocale( LC_ALL, "" ); @@ -575,8 +603,18 @@ main( int argc, char **argv ) ; if( main_option_plugin ) { +#if VIPS_ENABLE_DEPRECATED if( !im_load_plugin( main_option_plugin ) ) - vips_error_exit( NULL ); + vips_error_exit( NULL ); +#else /*!VIPS_ENABLE_DEPRECATED*/ + GModule *module; + + module = g_module_open( main_option_plugin, G_MODULE_BIND_LAZY ); + if( !module ) { + vips_error_exit( _( "unable to load \"%s\" -- %s" ), + main_option_plugin, g_module_error() ); + } +#endif } if( main_option_version ) @@ -634,6 +672,7 @@ main( int argc, char **argv ) break; } +#if VIPS_ENABLE_DEPRECATED /* Could be a vips7 im_function. We need to test for vips7 first, * since we don't want to use the vips7 compat wrappers in vips8 * unless we have to. They don't support all args types. @@ -656,6 +695,7 @@ main( int argc, char **argv ) if( action && !handled ) vips_error_clear(); +#endif /* Could be a vips8 VipsOperation. */ diff --git a/tools/vipsedit.c b/tools/vipsedit.c index a5b01d72..ef4b48e8 100644 --- a/tools/vipsedit.c +++ b/tools/vipsedit.c @@ -1,21 +1,23 @@ /* modify vips file header! - useful for setting resolution, coding... -very dangerous! -no way of setting non-used codes in variables like newxres -so need flags to show new parameter has been set.. boring -Copyright K.Martinez 30/6/93 -29/7/93 JC - -format added - - ==0 added to strcmp! -17/11/94 JC - - new header fields added -21/10/04 - - more header updates - -22/8/05 - - less-stupid-ified -20/9/05 - - rewritten with glib option parser, ready for xml options to go in - + * very dangerous! + * + * no way of setting non-used codes in variables like newxres + * so need flags to show new parameter has been set.. boring + * Copyright K.Martinez 30/6/93 + * + * 29/7/93 JC + * - format added + * - ==0 added to strcmp! + * 17/11/94 JC + * - new header fields added + * 21/10/04 + * - more header updates + * 22/8/05 + * - less-stupid-ified + * 20/9/05 + * - rewritten with glib option parser, ready for xml options to go in + * 18/6/20 kleisauke + * - avoid using vips7 symbols */ /* @@ -59,7 +61,6 @@ Copyright K.Martinez 30/6/93 #include #include -#include #include #include @@ -119,8 +120,8 @@ parse_pint( char *arg, int *out ) /* Might as well set an upper limit. */ *out = atoi( arg ); - if( *out <= 0 || *out > 1000000 ) - error_exit( _( "'%s' is not a positive integer" ), arg ); + if( *out <= 0 || *out > 1000000 ) + vips_error_exit( _( "'%s' is not a positive integer" ), arg ); } int @@ -129,8 +130,8 @@ main( int argc, char **argv ) GOptionContext *context; GOptionGroup *main_group; GError *error = NULL; - IMAGE *im; - unsigned char header[IM_SIZEOF_HEADER]; + VipsImage *im; + unsigned char header[VIPS_SIZEOF_HEADER]; if( VIPS_INIT( argv[0] ) ) vips_error_exit( "%s", _( "unable to start VIPS" ) ); @@ -158,10 +159,7 @@ main( int argc, char **argv ) if( !g_option_context_parse( context, &argc, &argv, &error ) ) #endif /*HAVE_G_WIN32_GET_COMMAND_LINE*/ { - if( error ) { - fprintf( stderr, "%s\n", error->message ); - g_error_free( error ); - } + vips_g_error( &error ); exit( -1 ); } @@ -178,12 +176,14 @@ main( int argc, char **argv ) exit( -1 ); } - if( !(im = im_init( argv[1] )) || - (im->fd = im__open_image_file( im->filename )) == -1 ) - error_exit( _( "could not open image %s" ), argv[1] ); - if( read( im->fd, header, IM_SIZEOF_HEADER ) != IM_SIZEOF_HEADER || - im__read_header_bytes( im, header ) ) - error_exit( _( "could not read VIPS header for %s" ), + if( !(im = vips_image_new_from_file( argv[1], NULL )) ) + vips_error_exit( _( "could not open image %s" ), argv[1] ); + + vips__seek( im->fd, 0, SEEK_SET ); + if( read( im->fd, header, VIPS_SIZEOF_HEADER ) != + VIPS_SIZEOF_HEADER || + vips__read_header_bytes( im, header ) ) + vips_error_exit( _( "could not read VIPS header for %s" ), im->filename ); if( endian ) { @@ -191,8 +191,8 @@ main( int argc, char **argv ) im->magic = VIPS_MAGIC_INTEL; else if( strcmp( endian, "big" ) == 0 ) im->magic = VIPS_MAGIC_SPARC; - else - error_exit( _( "bad endian-ness %s, " + else + vips_error_exit( _( "bad endian-ness %s, " "should be 'big' or 'little'" ), endian ); } if( xsize ) @@ -202,26 +202,36 @@ main( int argc, char **argv ) if( bands ) parse_pint( bands, &im->Bands ); if( format ) { - VipsBandFormat f; + int f; + + if( (f = vips_enum_from_nick( argv[0], + VIPS_TYPE_BAND_FORMAT, format )) < 0 ) + vips_error_exit( _( "bad format %s" ), format ); - if( (f = im_char2BandFmt( format )) < 0 ) - error_exit( _( "bad format %s" ), format ); im->BandFmt = f; - im->Bbits = im_bits_of_fmt( f ); + + /* We don't use this, but make sure it's set in case any + * old binaries are expecting it. + */ + im->Bbits = vips_format_sizeof( f ) << 3; } if( interpretation ) { - VipsInterpretation i; + int i; - if( (i = im_char2Type( interpretation )) < 0 ) - error_exit( _( "bad interpretation %s" ), + if( (i = vips_enum_from_nick( argv[0], + VIPS_TYPE_INTERPRETATION, interpretation )) < 0 ) + vips_error_exit( _( "bad interpretation %s" ), interpretation ); + im->Type = i; } if( coding ) { - VipsCoding c; + int c; + + if( (c = vips_enum_from_nick( argv[0], + VIPS_TYPE_CODING, coding )) < 0 ) + vips_error_exit( _( "bad coding %s" ), coding ); - if( (c = im_char2Coding( coding )) < 0 ) - error_exit( _( "bad coding %s" ), coding ); im->Coding = c; } if( xres ) @@ -233,31 +243,31 @@ main( int argc, char **argv ) if( yoffset ) im->Yoffset = atoi( yoffset ); - if( lseek( im->fd, 0, SEEK_SET ) == (off_t) -1 ) - error_exit( _( "could not seek on %s" ), im->filename ); - if( im__write_header_bytes( im, header ) || - im__write( im->fd, header, IM_SIZEOF_HEADER ) ) - error_exit( _( "could not write to %s" ), im->filename ); + if( vips__seek( im->fd, 0, SEEK_SET ) == (off_t) -1 ) + vips_error_exit( _( "could not seek on %s" ), im->filename ); + if( vips__write_header_bytes( im, header ) || + vips__write( im->fd, header, VIPS_SIZEOF_HEADER ) ) + vips_error_exit( _( "could not write to %s" ), im->filename ); if( setext ) { char *xml; size_t size; - if( !(xml = im__file_read( stdin, "stdin", &size )) ) - error_exit( "%s", _( "could not get ext data" ) ); + if( !(xml = vips__file_read( stdin, "stdin", &size )) ) + vips_error_exit( "%s", _( "could not get ext data" ) ); /* Strip trailing whitespace ... we can get stray \n at the - * end, eg. "echo | editvips --setext fred.v". + * end, eg. "echo | vipsedit --setext fred.v". */ while( size > 0 && isspace( xml[size - 1] ) ) size -= 1; - if( im__write_extension_block( im, xml, size ) ) - error_exit( "%s", _( "could not set extension" ) ); - im_free( xml ); + if( vips__write_extension_block( im, xml, size ) ) + vips_error_exit( "%s", _( "could not set extension" ) ); + g_free( xml ); } - im_close( im ); + g_object_unref( im ); /* We don't free this on error exit, sadly. */