AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
October 2005

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2005.10.15 12:43 "Small bug report, and error handler parameter issue", by Joris Van Damme
2005.10.15 16:06 "Re: Small bug report, and error handler parameter issue", by Frank Warmerdam
2005.10.15 16:24 "Re: Small bug report, and error handler parameter issue", by Joris Van Damme
2005.10.15 16:26 "Re: Small bug report, and error handler parameter issue", by Frank Warmerdam
2005.10.15 16:28 "Re: Small bug report, and error handler parameter issue", by Joris Van Damme

2005.10.15 16:24 "Re: Small bug report, and error handler parameter issue", by Joris Van Damme

Frank Warmerdam wrote:
> This change would break many existing applications that
> use libtiff (as I understand the change), and thus I don't
> think it could be contemplated except as part of a major
> generational step, presumably to libtiff 4.0.
>
> So, my position is that it should not be done till we are needing
> to do alot of other disruption.  These sort of API changes in a
> stable and established library like libtiff cause alot of waves.

Yes, I understand your reasons to keep API stable, and I totally agree.

But, I think there is a nice way to have our cake and eat it too, I
think is the expression. The following is from tif_warning.c and
tifio.h, but the error stuff works the same way:

typedef void (*TIFFErrorHandler)(const char*, const char*, va_list);

TIFFErrorHandler
TIFFSetWarningHandler(TIFFErrorHandler handler)
{
 TIFFErrorHandler prev = _TIFFwarningHandler;
 _TIFFwarningHandler = handler;
 return (prev);
}

void
TIFFWarning(const char* module, const char* fmt, ...)
{
 if (_TIFFwarningHandler) {
  va_list ap;
  va_start(ap, fmt);
  (*_TIFFwarningHandler)(module, fmt, ap);
  va_end(ap);
 }
}

We're lucky in that the calling of the application-level warning and
error handlers is packed, and is not used directly anywhere. From within
LibTiff, TIFFWarning is called, which in turn is the only place where
_TIFFwarningHandler is called directly. So we could change it to the
following:

typedef void (*TIFFErrorHandler)(const char*, const char*, va_list);
typedef void (*TIFFErrorHandlerExt)(TIFF*, const char*, const char*,
va_list);

TIFFErrorHandler
TIFFSetWarningHandler(TIFFErrorHandler handler)
{
 TIFFErrorHandler prev = _TIFFwarningHandler;
 _TIFFwarningHandler = handler;
 return (prev);
}

TIFFErrorHandlerExt
TIFFSetWarningHandlerExt(TIFFErrorHandlerExt handler)
{
 TIFFErrorHandlerExt prev = _TIFFwarningHandlerExt;
 _TIFFwarningHandlerExt = handler;
 return (prev);
}

void
TIFFWarning(TIFF* tif, const char* module, const char* fmt, ...)
{
 if (_TIFFwarningHandler) {
  va_list ap;
  va_start(ap, fmt);
  (*_TIFFwarningHandler)(module, fmt, ap);
  (*_TIFFwarningHandlerExt)(tif,module, fmt, ap);
  va_end(ap);
 }
}

So as to call the 'old' warning and error handlers the old way, so as to
not break old code, while additionally calling the 'new' warning and
error handlers the new way, so as to enable old cold to track down the
context of the reported warning or error.


Does this sound acceptable? Is it even correct? (I am not a C coder,
sorry if I made a stupid mistake somewhere.)


Joris Van Damme
info@awaresystems.be
http://www.awaresystems.be/
Download your free TIFF tag viewer for windows here:
http://www.awaresystems.be/imaging/tiff/astifftagviewer.html