Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-i.b-one.net (mx-i.one.com [91.198.169.56])
	by mail9.b-one.net (Postfix) with ESMTP id 9FAAB400125
	for <info@awaresystems.be>; Tue, 17 Feb 2009 19:06:37 +0100 (CET)
X-Virus-Scanned: by one.com
X-Spam-Score: 0
X-Spam-Level: 
X-Spam-Status: No, score=0 tagged_above=0 required=6 tests=[none]
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144])
	by mx-i.b-one.net (Postfix) with ESMTP id C10C18CCB
	for <info@awaresystems.be>; Tue, 17 Feb 2009 19:06:34 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id A03F01D18FBB9;
	Tue, 17 Feb 2009 13:05:48 -0500 (EST)
Received: from bosmailout15.eigbox.net (bosmailout15.eigbox.net [66.96.186.15])
	by lists.maptools.org (Postfix) with ESMTP id 6AC0D1D18FB08
	for <tiff@lists.maptools.org>; Tue, 17 Feb 2009 12:04:28 -0500 (EST)
Received: from bosmailscan09.eigbox.net ([10.20.15.9])
	by bosmailout15.eigbox.net with esmtp (Exim) id 1LZTMt-0005d0-S9
	for tiff@lists.maptools.org; Tue, 17 Feb 2009 12:04:23 -0500
Received: from bosimpout01.eigbox.net ([10.20.55.1])
	by bosmailscan09.eigbox.net with esmtp (Exim)
	id 1LZTMt-0006Eo-Id; Tue, 17 Feb 2009 12:04:23 -0500
Received: from bosauthsmtp03.eigbox.net ([10.20.18.3])
	by bosimpout01.eigbox.net with NO UCE
	id H0kC1b00c03yW760000000; Tue, 17 Feb 2009 07:44:12 -0500
X-EN-OrigOutIP: 10.20.18.3
X-EN-IMPSID: H0kC1b00c03yW760000000
Received: from [216.191.127.106] (helo=mojo)
	by bosauthsmtp03.eigbox.net with esmtpa (Exim)
	id 1LZTMi-0001EW-4u; Tue, 17 Feb 2009 12:04:12 -0500
From: "Philip Watkinson" <pwatkins@crawfordtech.com>
To: "'Joris Van Damme \(AWare Systems\)'" <info@awaresystems.be>,
	<tiff@lists.maptools.org>
Date: Tue, 17 Feb 2009 12:04:09 -0500
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook, Build 11.0.5510
Thread-Index: AcmNtfZxpInv6S43Tqq2jic2j2CuZwARF8kQAMmupSA=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-EN-UserInfo: 2bf9986308ae935707ad23145fa6683e:46981b1e5601c3c0ba1c453403d05b75
X-EN-AuthUser: pwatkins@crawfordtech.com
X-EN-OrigIP: 216.191.127.106
X-EN-OrigHost: unknown
Message-Id: <20090217170437.6AC0D1D18FB08@lists.maptools.org>
Subject: [Tiff] FW: Accessing tif->tif_clientdata within my own error
	andwarning functions
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
Reply-To: pwatkins@crawfordtech.com
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

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 

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
