AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2009.02.12 20:12 "[Tiff] Accessing tif->tif_clientdata within my own error and warning functions", by Philip Watkinson
2009.02.13 08:13 "Re: [Tiff] Accessing tif->tif_clientdata within my own error andwarning functions", by
2009.02.17 16:17 "Re: [Tiff] Accessing tif->tif_clientdata within my own error andwarning functions", by Philip Watkinson
2009.02.17 17:04 "[Tiff] FW: Accessing tif->tif_clientdata within my own error andwarning functions", by Philip Watkinson
2009.02.17 18:24 "Re: [Tiff] FW: Accessing tif->tif_clientdata within my own error andwarning functions", by Bob Friesenhahn
2009.02.17 21:11 "Re: [Tiff] Accessing tif->tif_clientdata within my own errorandwarning functions", by
2009.02.17 21:36 "Re: [Tiff] Accessing tif->tif_clientdata within my own error andwarning functions", by

2009.02.17 17:04 "[Tiff] FW: Accessing tif->tif_clientdata within my own error andwarning functions", by Philip Watkinson

Hi Joris,

Looking into the code a bit more. I see that calls to TIFFWaring() and TIFFError() have been replaced with calls TIFFWarningExt()and TIFFErrorExt().

Next question - It looks like the warning and error handling is not thread safe. I guess that I would have to add function pointers to TIFF?

Philip

-----Original Message-----

From: Philip Watkinson [mailto:pwatkins@crawfordtech.com] Sent: Tuesday, February 17, 2009 11:18 AM To: 'Joris Van Damme (AWare Systems)'; 'tiff@lists.maptools.org' Subject: RE: [Tiff] Accessing tif->tif_clientdata within my own error andwarning functions

Joris,

Went to ftp://ftp.remotesensing.org/pub/libtiff/ to download a newer version; I've got 3.7.1. Grabbed tiff-3.8.2.zip. I did not grab 3.9 or 4.0 because the filenames include "alpha" or "beta".

Noticed the global variable TIFFErrorHandlerExt in tif_warning.c. TIFFWarning() has been modified:

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

void
TIFFWarningExt(thandle_t fd, const char* module, const char* fmt, ...)
{
        va_list ap;
        va_start(ap, fmt);
        if (_TIFFwarningHandler)
                (*_TIFFwarningHandler)(module, fmt, ap);
        if (_TIFFwarningHandlerExt)
                (*_TIFFwarningHandlerExt)(fd, module, fmt, ap);
        va_end(ap);
}

Within TIFFWarning(), a warning extension function such as TIFFWarningExt() can now be called. The first parameter in TIFFWarningExt() is a pointer to the client data. But when TIFFWarningExt() is called from within TIFFWarning(), a NULL(0) pointer is used for the client data because a pointer to TIFF is not passed to TIFFWarning(). How can I access the client data (tif->tif_clientdata)?

Regards,
Philip

-----Original Message-----

From: Joris Van Damme (AWare Systems) [mailto:info@awaresystems.be]

Sent: Friday, February 13, 2009 3:13 AM
To: pwatkins@crawfordtech.com; tiff@lists.maptools.org
Subject: Re: [Tiff] Accessing tif->tif_clientdata within my own error
andwarning functions

Philip,

> For error and warning handling, the default action is write errors and
> warnings to standard error. You can create your own error and warning
> functions and set them with TIFFSetErrorHandler() (tif_error.c) and
> TIFFSetWarningHandler() (tif_warning.c). Error and warning messages
> are created with TIFFError() and TIFFWarning(). These functions can
> then call my own error and warning functions.
>
> I would like to be able to access my structure pointed to by
> TIFF->tif_clientdata within my functions. I would like to buffer error
> TIFF->and
> warning messages in my structure instead of using stderr.
> Unfortunately a pointer to TIFF is not passed to TIFFError() or
TIFFWarning().
>
> Is there another to control warning and error messages? I'm using
> version 3.7.1.
>
> Is it possible in a future release to include access to
> tif->tif_clientdata
> for custom error and warning functions?

We've all had the same problem at one time or another, and I've cured it
recently. In recent versions, the interface you describe here still exists
for backwards compatibility, but there is an added interface that is much
the same only it has an 'Ext' appended to the function names and it includes
the tif->tif_clientdata so as to enable retrieving the context when handling
warnings and errors.

I can't say from the top of my head in what version the extended interface
got added. I don't think 3.7.1 has it. Do a library-wide search on
'TIFFSetErrorHandlerExt'. If that doesn't yield any search results, then
you're out of luck and might need to upgrade to a newer version.

Some people manage to get a context from a global var. Of course, that only
works as long as you've at most one TIFF object in your total application at
any given time. Some get a context from a threadvar. Of course, that only
works if you've at most one TIFF object per thread at any given time. If
even the last condition does not apply to your setup, you will indeed need
to use the 'Ext' error/warning handler interface in newer versions.

Best regards,

Joris