capture tiff warnings during startup

We were not capturing warnings from libtiff until we used libtiff
ourselves. Other libraries whcih we call, such as ImageMagick, could use
libtiff and generate an uncaptured warning.

On Windows these warnings each produced a popup.
This commit is contained in:
John Cupitt 2012-11-14 14:44:21 +00:00
parent 4ab937a8b6
commit efcc53859a
6 changed files with 31 additions and 22 deletions

View File

@ -1,3 +1,6 @@
14/11/12 started 7.30.6
- capture tiff warnings earlier
14/11/12 started 7.30.5
- fix libtool version mess up (thanks Benjamin)

View File

@ -2,7 +2,7 @@
# also update the version number in the m4 macros below
AC_INIT([vips], [7.30.5], [vipsip@jiscmail.ac.uk])
AC_INIT([vips], [7.30.6], [vipsip@jiscmail.ac.uk])
# required for gobject-introspection
AC_PREREQ(2.62)
@ -17,7 +17,7 @@ AC_CONFIG_MACRO_DIR([m4])
# user-visible library versioning
m4_define([vips_major_version], [7])
m4_define([vips_minor_version], [30])
m4_define([vips_micro_version], [5])
m4_define([vips_micro_version], [6])
m4_define([vips_version],
[vips_major_version.vips_minor_version.vips_micro_version])
@ -37,7 +37,7 @@ VIPS_VERSION_STRING=$VIPS_VERSION-`date`
# binary interface changes not backwards compatible?: reset age to 0
LIBRARY_CURRENT=33
LIBRARY_REVISION=7
LIBRARY_REVISION=8
LIBRARY_AGE=2
# patched into include/vips/version.h

View File

@ -36,8 +36,7 @@ extern "C" {
extern const char *vips__foreign_tiff_suffs[];
void vips__thandler_error( const char *module, const char *fmt, va_list ap );
void vips__thandler_warning( const char *module, const char *fmt, va_list ap );
void vips__tiff_init( void );
int vips__tiff_write( VipsImage *in, const char *filename,
VipsForeignTiffCompression compression, int Q,

View File

@ -229,13 +229,13 @@ typedef struct {
* more than one thread, but vips_error and vips_warn have mutexes in, so that's
* OK.
*/
void
static void
vips__thandler_error( const char *module, const char *fmt, va_list ap )
{
vips_verror( module, fmt, ap );
}
void
static void
vips__thandler_warning( const char *module, const char *fmt, va_list ap )
{
char buf[256];
@ -244,6 +244,16 @@ vips__thandler_warning( const char *module, const char *fmt, va_list ap )
vips_warn( module, "%s", buf );
}
/* Call this during startup. Other libraries may be using libtiff and we want
* to capture any messages they send as well.
*/
void
vips__tiff_init( void )
{
TIFFSetErrorHandler( vips__thandler_error );
TIFFSetWarningHandler( vips__thandler_warning );
}
/* Test for field exists.
*/
static int
@ -1506,8 +1516,7 @@ istiffpyramid( const char *name )
{
TIFF *tif;
TIFFSetErrorHandler( vips__thandler_error );
TIFFSetWarningHandler( vips__thandler_warning );
vips__tiff_init();
if( (tif = get_directory( name, 2 )) ) {
// We can see page 2 ... assume it is.
@ -1529,8 +1538,7 @@ vips__tiff_read( const char *filename, VipsImage *out, int page )
printf( "tiff2vips: libtiff starting for %s\n", filename );
#endif /*DEBUG*/
TIFFSetErrorHandler( vips__thandler_error );
TIFFSetWarningHandler( vips__thandler_warning );
vips__tiff_init();
if( !(rtiff = readtiff_new( filename, out, page )) )
return( -1 );
@ -1558,8 +1566,7 @@ vips__tiff_read_header( const char *filename, VipsImage *out, int page )
{
ReadTiff *rtiff;
TIFFSetErrorHandler( vips__thandler_error );
TIFFSetWarningHandler( vips__thandler_warning );
vips__tiff_init();
if( !(rtiff = readtiff_new( filename, out, page )) )
return( -1 );
@ -1583,10 +1590,7 @@ vips__istifftiled( const char *filename )
TIFF *tif;
gboolean tiled;
/* Override the default TIFF error handler.
*/
TIFFSetErrorHandler( vips__thandler_error );
TIFFSetWarningHandler( vips__thandler_warning );
vips__tiff_init();
if( !(tif = TIFFOpen( filename, "rm" )) ) {
vips_error_clear();

View File

@ -123,6 +123,13 @@ vips_foreign_load_tiff_class_init( VipsForeignLoadTiffClass *class )
VipsForeignClass *foreign_class = (VipsForeignClass *) class;
VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class;
/* Other libraries may be using libtiff, we want to capture tiff
* warning and error as soon as we can.
*
* This class init will be triggered during startup.
*/
vips__tiff_init();
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;

View File

@ -1474,7 +1474,6 @@ gather_pyramid( TiffWrite *tw )
return( 0 );
}
int
vips__tiff_write( VipsImage *in, const char *filename,
VipsForeignTiffCompression compression, int Q,
@ -1493,10 +1492,7 @@ vips__tiff_write( VipsImage *in, const char *filename,
printf( "tiff2vips: libtiff version is \"%s\"\n", TIFFGetVersion() );
#endif /*DEBUG*/
/* Override the default TIFF error handler.
*/
TIFFSetErrorHandler( vips__thandler_error );
TIFFSetWarningHandler( vips__thandler_warning );
vips__tiff_init();
/* Check input image.
*/