# HG changeset patch # User magedrifaat # Date 1660157991 -7200 # Node ID d701c6a4cda1a4454619e114283a749172ec5da3 # Parent 28817158ca86b6ad9e7a92e84594d9daaeb7f8ef Tiff: improved handling LibTIFF error output silencing. diff -r 28817158ca86 -r d701c6a4cda1 libinterp/corefcn/__tiff__.cc --- a/libinterp/corefcn/__tiff__.cc Wed Aug 10 20:46:56 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Wed Aug 10 20:59:51 2022 +0200 @@ -16,7 +16,8 @@ #if defined (HAVE_TIFF) # include -TIFFErrorHandler tiff_default_handler = NULL; +TIFFErrorHandler tiff_default_error_handler = NULL; +TIFFErrorHandler tiff_default_warning_handler = NULL; #endif namespace octave @@ -2373,12 +2374,30 @@ "Enables or Disables error output from LibTIFF") { #if defined (HAVE_TIFF) - if (args (0).bool_value ()) - TIFFSetErrorHandler (tiff_default_handler); - else if (tiff_default_handler == NULL) - tiff_default_handler = TIFFSetErrorHandler (NULL); + // Get the default error handlers the first time this function is called + if (tiff_default_error_handler == NULL) + { + tiff_default_error_handler = TIFFSetErrorHandler (NULL); + tiff_default_warning_handler = TIFFSetWarningHandler (NULL); + } + + if (args.length () == 0) + error ("No state argument provided"); + + if (! args(0).is_bool_scalar ()) + error ("Expected logical value as argument"); + + // Set the error and warning handlers according to the bool parameter + if (args(0).bool_value ()) + { + TIFFSetErrorHandler (tiff_default_error_handler); + TIFFSetWarningHandler (tiff_default_warning_handler); + } else - TIFFSetErrorHandler (NULL); + { + TIFFSetErrorHandler (NULL); + TIFFSetWarningHandler (NULL); + } return octave_value_list (); #else